How to find UID of an app installed on Android and use it as a shell user?
Android inherits from Linux the concept of shell, which is the core component of Linux login process. But there is no concept of Linux console login on Android (1) because it boots directly to GUI. However it makes use of Discretionary Access Control (DAC) of Linux kernel which is based on UIDs / GIDs and permission mode. Every installed app is considers as a *NIX user and is assigned a unique UID at install time. See this answer for more details on this.
You can get UID of Automate app from file /data/system/packages.list or by executing id -u from within app:

~# awk '/^com.llamalab.automate/ {print $2}' /data/system/packages.list
10106


Since you want a remote login from local machine using a ssh binary (built from standard Linux source) which is to be executed by Automate app i.e. with UID 10106, the key file must also be owned by UID 10106. The only place on device which is owned by UID 10106 is the directory /data/data/com.llamalab.automate, so this should be set as $HOME for ssh and where the key should be placed under directory .ssh owned by UID/GID 10106:

~# mkdir /data/data/com.llamalab.automate/.ssh
~# ssh-keygen -f /data/data/com.llamalab.automate/.ssh/id_rsa
~# chmod 0700 /data/data/com.llamalab.automate/.ssh
~# chown -R 10106.10106 /data/data/com.llamalab.automate/.ssh


Create file /etc/passwd with a single line: user:x:10106:10106::/data/data/com.llamalab.automate:/system/bin/sh where user is any username of your choice. You can also use adduser:

~# touch /etc/passwd
~# busybox adduser -D -H -h /data/data/com.llamalab.automate -s /system/bin/sh -u 10106 user


Also add -o StrictHostKeyChecking=no to ssh command so that new server is added to known_hosts without user interaction.

However if the ssh binary is built specifically for Android to be used with an app, it must have its $HOME already hard-coded which can't be changed using /etc/passwd. In this case you can try something like ssh -i &lt;path/to/key&gt; -o UserKnownHostsFile=&lt;path/to/known_hosts&gt; &lt;user&gt;@&lt;IP&gt;. Permissions must be set and both paths must be accessible by executing app.

PS:

Please note that UID 10106 must be member of group aid_inet (GID 3003) for ssh to be able to make connections. All apps with android.permission.INTERNET are member of this group. Or you can add a line to /etc/group: internet:x:3003:user. Or using addgroup:

~# touch /etc/group
~# busybox addgroup -g 3003 internet
~# busybox addgroup user internet


However this is useful only for programs which perform login (setgroups()) like su, sshd etc.

For more details on how Android lacks Linux's login mechanism, see this answer.