Thursday, September 30, 2021

Accessing android phone via ssh using termux

The ability to access your phone remotely is very useful. I frequently used this technique to copy files to and from my phone and checking my battery status while the phone is charging without actually holding the phone.

First and foremost, we have to install termux. You can install it from google playstore by clicking here


Once installed, fire up termux, and install openssh:

$ pkg install openssh

Then, create a password for the default user. The default user is u0_a274.

$ passwd

Then, launch an sshd daemon using below command to start openssh server in the phone, on port 1234 (the port can be any number above 1000).

$ sshd -p 1234

Check your ip address. using below command.

$ ip address 

Let's say our phone's ip address is 192.168.0.179. Make sure your desktop/laptop is connected to the same network as the phone's wifi connection. Fire up a terminal, and ssh to the ip address.

$ ssh u0_a274@192.168.0.179 -p 1234 



Congratulations, you are now connected to your phone, via ssh.

 

Monday, September 6, 2021

Enabling passwordless ssh for Synology DSM version 6

Synology DSM 6.0 does not allow, let alone passwordless ssh by default. In order to enable that, so that we can have automated backup to Synology NAS, below are the steps:

1. Enable User Home in User  Advanced


 
2. Enable SSH in "Terminal & SNMP"  Terminal


3. (Recommended) Create a user, and add the user into administrator group by going to User → Create. As an example, I created a user called dbbackup.



4. Change permission of the user's home directory to 755. You can do this by ssh'ing into synology as admin, and run below command
$ ssh administrator@synology-ip
$ sudo chmod 775 /var/services/homes/dbbackup 

$ exit 


5. Ssh into synology as your new user. Edit below lines in /etc/ssh/sshd_config, and save the file.
$ ssh dbbackup@synology-ip
$ sudo vi /etc/ssh/sshd_config
...
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
ChallengeResponseAuthentication no
...
6. Restart sshd service
$ sudo synoservicectl --restart sshd

7. Exit from synology shell, and create a pair of ssh key in client machine, and press enter for all the questions

$ ssh-keygen

8. Transfer the public key into synology

$ ssh-copy-id dbbackup@synology-ip

9. Test you ssh connection to synology. You should be able to ssh without password into synology.

$ ssh dbbackup@synology-ip