20171112-ssh_into_android.md (1656B)
1 In a [previous post](/content/20170614-termux_on_android.html) I talked about installing [termux](https://termux.com) on an Android device. This tool makes it easy to ssh into our other Linux systems, but what if we want to ssh into our Android device? 2 3 Unfortunately password login doesn't work on Android and if you haven't rooted your device you have limited permissions. Instead we can use ssh keys. 4 5 If you don't already have an ssh key pair then on you Linux system run 6 ``` 7 ssh-keygen -t rsa 8 ``` 9 10 If you accepted the defaults this will create two files under your user's .ssh directory, `id_rsa` and `id_rsa.pub`. 11 12 Make sure `sshd` is running on your Linux machine (requires the OpenSSH package) 13 ``` 14 systemctl status sshd 15 ``` 16 17 If it's not installed run the following (if it's just not running omit the first command) 18 ``` 19 sudo pacman -S openssh 20 sudo systemctl start sshd 21 ``` 22 23 Also make a note of the IP address 24 ``` 25 ip a 26 ``` 27 28 Next, from termux on your Android device copy down the public key you just created 29 ``` 30 scp pyratebeard@192.168.1.3:.ssh/id_rsa.pub ./id_rsa.pub 31 ``` 32 33 Now add the public key to the `authorized_keys` list 34 ``` 35 cat id_rsa.pub >> .ssh/authorized_keys 36 ``` 37 38 Almost there. Finally we need to install OpenSSH on termux and start the daemon 39 ``` 40 apt install openssh 41 sshd 42 ``` 43 44 Make a note of the IP address of your Android device 45 ``` 46 ip a 47 ``` 48 49 That's it! You can now ssh from your Linux machine onto your Android device using port 8022 50 ``` 51 ssh 192.168.1.4 -p 8022 52 ``` 53 54 If you need to specify a user for the above command then from termux run 55 ``` 56 whoami 57 ``` 58 and add the user to the ssh command 59 ``` 60 ssh 192.168.1.4 -p 8022 -l u0_a161 61 ``` 62 63