How can I access my Ubuntu phone over ssh?
With the official final release Ubuntu for Phones ships the "android-gadget-service" tool with which you can manage adb, mtp, USB tethering and ssh.
Connect your device via USB, enable Developer Mode in:
"System-Settings->About This Phone->Developer Mode"
...and run (from your PC, make sure to have the phone screen unlocked, else adb will refuse to let you in):
adb shell android-gadget-service enable ssh
Copy your public key to the Phone:
adb shell mkdir /home/phablet/.ssh
adb push ~/.ssh/id_rsa.pub /home/phablet/.ssh/authorized_keys
adb shell chown -R phablet.phablet /home/phablet/.ssh
adb shell chmod 700 /home/phablet/.ssh
adb shell chmod 600 /home/phablet/.ssh/authorized_keys
Now you can look up your IP on the phone and use ssh to connect:
adb shell ip addr show wlan0|grep inet
ssh phablet@<IP from above command>
To activate ssh access entirely over wifi, without developer mode on the phone, without any special tooling on your computer and without using USB:
- If you don't already have an ssh keypair, type
ssh-keygen
on your computer and follow the instructions to generate one. - Install the Terminal app on the phone from the App Store.
-
Open a Terminal and type (this is easier with the phone in a landscape orientation):
sudo setprop persist.service.ssh true mkdir -pm700 ~/.ssh ip addr nc -l 1234 > ~/.ssh/authorized_keys
(the last command will hang; this is expected)
Look for your phone's IP address in the Terminal as returned by the
ip addr
command above.-
On your computer, type (replacing
192.0.2.1
with your phone's IP address from above):nc 192.0.2.1 1234 < ~/.ssh/id_rsa.pub
If successful, the last command on your phone's Terminal will now succeed.
-
On your computer, type (again replacing
192.0.2.1
with your phone's IP address from above):ssh [email protected]
If your phone's IP address changes, you will need to use
ip addr
in the Terminal app on your phone again and adjust your ssh command accordingly.
OpenSSH server is now (as of 13-Sep-2013) pre-loaded with Ubuntu Touch install. However, it is also disabled by default. You also don't want SSH operating from root.
You need to type the following, using a USB connection to the device:
adb shell
su - phablet
sudo tee /etc/init/ssh.override < /dev/null
To revert to disabled
echo "manual" | sudo tee /etc/init/ssh.override
UPDATE: (09-Mar-2014)
The answer above is no longer current.
As of early March 2014, while the file
/etc/init/ssh.override
still exists, changing its contents does not allow SSH (actually the sshd daemon) to run on startup.The recent builds (tested for 226, but possibly earlier) now support a new meta-flag persist.service.ssh, to allow SSH (sshd daemon) to re-start on startup.
Get to command prompt (on device)
adb shell
su - phablet
Start SSH, and set flag
sudo service ssh start
sudo setprop persist.service.ssh true
Restart device
sudo reboot
The SSH daemon should auto-start
sudo service ssh status
To disable SSH auto-start, change the flag:
sudo setprop persist.service.ssh false