通过 ssh 访问 shell

您可以使用 ssh 从 PC 访问 shell。 这对于调试或更高级的shell 使用来说非常有用

You need a ssh key pair for this. Logging in via password is disabled by default.

创建你的公钥

If not already created, create your public key, default choices should be fine for LAN, you can leave empty password if you don’t want to deal with it each time:

ssh-keygen

将公钥复制到您的设备

然后,您需要将公钥传输到您的设备。 有许多方法实现。 例如:

  • Connect the ubports device and the PC with a USB cable. Then copy the file using your filemanager.

  • Or transfer the key via the internet by mailing it to yourself, or uploading it to your own cloud storage, or webserver, etc.

  • You can also connect via adb and use the following command to copy it:

    adb push ~/.ssh/id_rsa.pub /home/phablet/
    

配置您的设备

Now you have the public key on the UBports device. Let’s assume it’s stored as /home/phablet/id_rsa.pub. Use the terminal app or and adb connection to perform the following steps on your phone.

mkdir /home/phablet/.ssh
chmod 700 /home/phablet/.ssh
cat /home/phablet/id_rsa.pub >> /home/phablet/.ssh/authorized_keys
chmod 600 /home/phablet/.ssh/authorized_keys
chown -R phablet.phablet /home/phablet/.ssh

现在开启 SSH 服务器:

sudo android-gadget-service enable ssh

连接

Now everything is set up and you can use ssh

ssh phablet@<ip-address>

Of course you can now also use scp or sshfs to transfer files.