Whenever I try to run apt-get install openssh-server I get the following errors:

root@ubuntu-phablet:/home/hablet# apt-get install openssh-server
W: Not using locking for read only lock file /var/lib/dpkg/lock
E: Unable to write to /var/cache/apt
E: The package lists or status file could not be parsed or opened.
  • Exactly the same error – user195123 Sep 22 '13 at 14:10
  • Same error for me doing same thing - ubuntu 11.04. – Malee Sep 22 '13 at 14:13
  • 1
    @Malee 11.04 is end of life, you can't get help for 11.04 here because of that. Upgrade to 12.04 or newer, or to a supported release, and then we can help you fix it. – Thomas Ward Sep 22 '13 at 16:35
  • 1
    Ubuntu touch does not have the software center yet and updating is terminal only, which i did not do as i tried to install openssh. – user195123 Sep 22 '13 at 17:47
  • Ok since i did not change too much yet, do you think formatting my storage and reflashing ubuntu helps? – user195123 Sep 22 '13 at 19:00

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>
  • Works great, but the last command will show no IP if the network interface is not named wlan0. Mine was wlan2 for some reason. – Cos64 Mar 28 '15 at 6:32
  • The command: adb push ~/.ssh/id_rsa.pub /home/phablet/.ssh/authorized_keys Gives me: cannot stat '/home/tenleftfingers/.ssh/id_rsa.pub': No such file or directory – TenLeftFingers May 13 '15 at 17:05
  • No need for Developer Mode or making the image writable. See SSH Ubuntu Touch for an easy, working solution. As always with password-less authentication you need to place a /home/phablet/.ssh/authorized_keys file (with a public key of the PC you're using to access the Ubuntu Touch device) on your device. Running ssh -v phablet@<ip-address> (verbose) helps to debug login or permission issues. – Peterino Feb 12 '16 at 13:04
  • @orga Does it broadcast with zeroconf (avahi-daemon)? That way I can see my device on nautilus and transfer files over sftp. – Khurshid Alam Apr 27 '16 at 14:31
  • I also had to add permissions: chmod o-w ~/ – Mantas Vaitkūnas Jul 5 '16 at 14:02

To activate ssh access entirely over wifi, without developer mode on the phone, without any special tooling on your computer and without using USB:

  1. If you don't already have an ssh keypair, type ssh-keygen on your computer and follow the instructions to generate one.
  2. Install the Terminal app on the phone from the App Store.
  3. 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)

  4. Look for your phone's IP address in the Terminal as returned by the ip addr command above.

  5. 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.

  6. On your computer, type (again replacing 192.0.2.1 with your phone's IP address from above):

    ssh phablet@192.0.2.1
    
  7. 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.

  • 2
    Very informative answer as it does away with the adb shell and USB cable. Two thumbs up! – Stunts Apr 3 '15 at 11:22
  • Indeed Veryvery usefull answer. +2 – zloster Jun 6 '15 at 7:33
  • @ogra (who knows better than me) tells me that sudo android-gadget-service enable ssh superceded sudo setprop persist.service.ssh true and should be used instead, but I haven't tested this. – Robie Basak Jun 23 '15 at 9:04
  • This should be the top answer as with the BQ Aquarius 5 the phone can't be discovered with the android method. – Kat Amsterdam Jan 11 '16 at 19:01

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
  • why do you need to sudo everything after going su -? – Octopus Jan 16 '15 at 9:30
  • The line su - phablet changes the user to phablet, not super-user. It is generally best practice to use least privilege, so as to be less vulnerable to attack. – david6 Jan 16 '15 at 9:55
  • this answer needs updating, look at @ogra's – sergiusens Mar 25 '15 at 17:54
  • Will need to review and try that method first. – david6 Mar 25 '15 at 20:03

Try making it writable and reboot:

touch /userdata/.writable_image

Edit: When you build it use the --pending switch Updates to phablet-flash

Edit: System images now the recommended way to deploy and update Ubuntu Touch

  • This answer is no longer relevant. – popey Mar 20 '15 at 8:46

Install Ubuntu SDK and click "Open SSH connection do the device" in the devices panel. Bonus: you won't resist to writing a new Scope...

I have just found a faster (quick and dirty) way (Attention: it is not secure!):

1) Install the terminal app and open it

2) switch to root

sudo su

(enter you screen lock password)

2) Enter the following commands:

echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config
echo "AllowUsers phablet" >> /etc/ssh/sshd_config
/usr/sbin/sshd

Now your ssh server is running and it will accept your screen lock code as a password! Attention: it is very easy to brute-force now! Please change your settings immediately (now you can do it in a comfortable way, after you connect via ssh from you PC).

Since you run the sshd manually, the /etc/init/ssh.override file is not applied anymore...

So to connect from your PC:

ssh phablet@x.x.x.x

where x.x.x.x is an IP-address of your phone, which you can find by typing

ifconfig

in the terminal of your phone.

Enjoy!

UPDATE: it could be, that after update, sshd is failing to start because it cannot open host keys, then just regenerate them:

/usr/bin/ssh-keygen -A

If it fails because /var/run/sshd is missing, just create it:

mkdir /var/run/sshd
chmod 755 /var/run/sshd

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.