Shell access via SSH
To access a shell from your PC, you can use SSH, which can be useful for advanced shell usage or debugging. SSH key-pair is required for logging in, as password login is disabled by default. To create your public key, use the “ssh-keygen” command, and default options should suffice for LAN. You may leave the password field empty if desired.
To transfer the public key to your device, there are multiple options available, such as using a USB cable to connect the UBports device and PC, then copying the file using a file-manager. Alternatively, you can email the key to yourself or upload it to your cloud storage, web server, etc. If supported, you can also connect via adb and copy the key using the “adb push ~/.ssh/id_rsa.pub /home/phablet/” command.
To configure your device, assuming that the public key is saved as /home/phablet/id_rsa.pub, you need to perform the following steps on your UBports device using either the terminal app or an ADB connection.
First, create a directory for SSH using the command “mkdir /home/phablet/.ssh“. Then, set the permissions using “chmod 700 /home/phablet/.ssh“. Append the public key to the authorized keys file using “cat /home/phablet/id_rsa.pub >> /home/phablet/.ssh/authorized_keys” and set the file permissions using “chmod 600 /home/phablet/.ssh/authorized_keys“. Finally, set the ownership using “chown -R phablet:phablet /home/phablet/.ssh“.
To start the SSH server, if you are using an Android, use the command “sudo android-gadget-service enable ssh“. If you are using a Linux, use “sudo service ssh start“.
Once everything is set up, you can use SSH to connect to your UBports device. Use the command “ssh phablet@ubuntu-phablet” to connect. If that doesn’t work, try using the IP address of your device with the command “ssh phablet@<ip-address>“.
To find the IP address of your UBports device, open the Terminal app on your device and enter the command “hostname -I“. The output will show a list of IP addresses separated by spaces. Use the IP address that matches your subnet. For example, if the output on your PC or laptop is “192.168.42.41 2001:982:89e9:1:bc6b:758:7ba2:c190” and the output on your phone is “10.55.74.177 192.168.42.52 2001:982:89e9:1:ef68:5f7c:3db4:c0d3“, you should use the second IP address.
Additionally, you can use SCP or SSHFS to transfer files.