Login without password from iPhone on remote box
If I want to connect to my remote box from my iPhone, I don’t like very much to type “ssh user@remote.box.be” and then the password … it’s just too much!
Here’s how you use private and public keys and a very small script to connect … faster!
On your iPhone (thus via an SSH client, of via MobileTerminal) make sure you’re doing this as the “mobile” user:
iPhone3G:/bin root# su mobile iPhone3G:/bin mobile$
Then type the following command:
iPhone3G:~/.ssh mobile$ ssh-keygen -r dsa
Now you have 2 new files in the .ssh directory:
iPhone3G:~/.ssh mobile$ ls -al total 12 drwx------ 2 mobile mobile 170 Aug 25 21:30 . drwxr-xr-x 7 mobile mobile 306 Aug 11 17:52 .. -rw------- 1 mobile mobile 672 Aug 25 21:30 id_dsa -rw-r--r-- 1 mobile mobile 605 Aug 25 21:30 id_dsa.pub -rw-r--r-- 1 mobile mobile 1326 Aug 16 10:21 known_hosts
Use Winscp to copy the id_dsa.pub file to your remote box, and put it in your ~/.ssh directory, renaming it to authorized_keys. If you already have an authorized_keys file there, you’ll need to append the contents of id_dsa.pub to it, with:
selder@derelict:~/.ssh$ cat id_dsa.pub >> authorized_keys
Now, create a file with the name of your remote box (or a shortname) in the /bin directory on your iPhone:
iPhone3G:/bin mobile$ cat remote_box #!/bin/sh ssh user@remote.box.be
And make sure everyone can execute it:
iPhone3G:/bin mobile$ chmod 755 remote_box iPhone3G:/bin mobile$ ls -al remote_box -rwxr-xr-x 1 root wheel 41 Aug 25 22:11 remote_box*
Et voila! By typing “remote_box” in MobileTerminal on my iPhone I am immediately connected to my remote box, without typing the password!
Ah, maybe the most important part: just be very careful now … remember to remove the entry in the authorized_keys file on your remote box if your iPhone has been stolen or something … with that key someone else could have complete control over your box without having to type a password!
Thanks to _bs who explained me 10 years ago :)
[...] Auto login crap with public and private keys and stuff see here. [...]