How can I access my Ubuntu phone over ssh?
Solution 1
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>
Solution 2
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.
Solution 3
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
Related videos on Youtube
Starwop
Updated on September 18, 2022Comments
-
Starwop over 1 year
I'm creating a Poker evaluater, but I'm having trouble figuring out how to check for "straight" combinations (I also need to know what cards made the combination).
I have a list of cards, so what I need to figure out is the following:
Does the list contain an ace or not?
If yes:
- Create a new list where ace is high.
- Create a new list where ace is low.
- Run check on both lists and return whichever has the higher count of cards that are in a straight combination.
If No:
- Run check on list and return the cards that are in a straight combination.
How to check for a straight combination:
Run through the list and check whether the current card's rank + 1 is equal to the previous card's rank.
Using this method we will run into an issue....
Take the following into consideration:
- King
- Queen
- Jack
- Three
- Two
The result would be:
- King = Nothing = False
- Queen = King = True
- Jack = Queen = True
- Three = Jack = False
- Two = Three = True
That result is no good, the result in that case should be: King, Queen, Jack.
I'm not sure how to put this into code in a smart way, or just in a way that would work. I have tried doing LINQ and I have tried using for loops.
Here's the card class that I have made:
Public Enum CardRank Two = 2 Three = 3 Four = 4 Five = 5 Six = 6 Seven = 7 Eight = 8 Nine = 9 Ten = 10 Jack = 11 Queen = 12 King = 13 Ace = 14 End Enum Public Enum CardSuit Club = 1 Diamond = 2 Heart = 3 Spade = 4 End Enum Public Class Card Public Rank As CardRank Public Suit As CardSuit #Region "Constructor" Sub New() End Sub Sub New(ByVal Rank As CardRank, ByVal Suit As CardSuit) Me.Rank = Rank Me.Suit = Suit End Sub #End Region Public Overrides Function ToString() As String Return [Enum].GetName(GetType(CardRank), Rank) + " of " + [Enum].GetName(GetType(CardSuit), Suit) End Function End Class
Copy this to quickly get started:
Dim Deck As New List(Of Card) Dim Cards As List(Of Card) = New Card() {New Card(CardRank.King, CardSuit.Spade), New Card(CardRank.Queen, CardSuit.Heart), New Card(CardRank.Jack, CardSuit.Club), New Card(CardRank.Three, CardSuit.Spade), New Card(CardRank.Two, CardSuit.Diamond)}.ToList() 'Add deck For Each Suit As CardSuit In [Enum].GetValues(GetType(CardSuit)) For Each Rank As CardRank In [Enum].GetValues(GetType(CardRank)) Deck.Add(New Card(Rank, Suit)) Next Next For Each Card As Card In Cards Deck.Remove(Card) Next
Maybe I'm going about this the wrong way?
EDIT: A straight is five cards of sequential rank. Note that in holdem, Aces can be high or low. EDIT: Here's how I list my cards atm. (Can be altered to fit other methods of course)
Dim tempList = Cards.GroupBy(Function(card) card.Rank).Reverse().OrderByDescending(Function(group) group.Count()).SelectMany(Function(group) group).ToList()
-
Admin over 10 yearsExactly the same error
-
Admin over 10 yearsSame error for me doing same thing - ubuntu 11.04.
-
Admin over 10 years@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.
-
Admin over 10 yearsUbuntu touch does not have the software center yet and updating is terminal only, which i did not do as i tried to install openssh.
-
Admin over 10 yearsOk since i did not change too much yet, do you think formatting my storage and reflashing ubuntu helps?
-
Admin over 10 yearsTried it, still getting the same mistake...
-
Admin over 10 yearsWhat command do you reflash with?
-
Admin over 10 yearsI follow the exact instructions on wiki.ubuntu.com/Touch/Install, the command is phablet-flash i will try another version now
-
Admin over 10 yearsWhy are you using Ubuntu 11.04?
-
Karl Gjertsen over 8 yearsYour code shows your classes, but not how you have attempted to rank them. Do you have some more code to show?
-
Starwop over 8 yearsI have edited my main post, please take another look. Thank you :)
-
Octopus over 9 yearswhy do you need to sudo everything after going su -?
-
david6 over 9 yearsThe 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. -
undsoft about 9 yearsThis answer is no longer relevant.
-
david6 about 9 yearsWill need to review and try that method first.
-
Cos64 about 9 yearsWorks great, but the last command will show no IP if the network interface is not named
wlan0
. Mine waswlan2
for some reason. -
Stunts about 9 yearsVery informative answer as it does away with the adb shell and USB cable. Two thumbs up!
-
TenLeftFingers about 9 yearsThe 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
-
zloster almost 9 yearsIndeed Veryvery usefull answer. +2
-
Anish almost 9 years@ogra (who knows better than me) tells me that
sudo android-gadget-service enable ssh
supercededsudo setprop persist.service.ssh true
and should be used instead, but I haven't tested this. -
Damien_The_Unbeliever over 8 yearsDoesn't this ignore the existence of suits? E.g. a hand composed of 4H + 4S + 6D + 8C + 8H. Min = 4, Max = 8, (Min + Max) * 5 / 2 = 30. Sum = 30. But no straight.
-
Michel Keijzers over 8 years@Damien_The_Unbeliever You are fully right; I changed the algorithm.
-
Damien_The_Unbeliever over 8 yearsI think you need to
&=
or insert some early breaks in those loops. Same hand again ends up assigningisStraight
the valuestrue, false, true, false, true
and then returns true. -
Michel Keijzers over 8 years@Damien_The_Unbeliever True .. and fixed (hard to do without a compiler nearby and test case.
-
Peterino over 8 yearsNo 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. Runningssh -v phablet@<ip-address>
(verbose) helps to debug login or permission issues. -
Khurshid Alam about 8 years@orga Does it broadcast with zeroconf (avahi-daemon)? That way I can see my device on nautilus and transfer files over sftp.
-
Mantas Vaitkūnas almost 8 yearsI also had to add permissions: chmod o-w ~/
-
Alan Mimms about 5 yearsFor me, the phablet was only answering on IPv6. So I had to use
ssh -6 phablet@ipv6-addr%ethernet-interface
to get it to work.