Automatic Login For SSH/SFTP on Ubuntu

There are just three simple steps needed to automate your SSH/SFTP logins to remote Unix/Unix-like servers from your Ubuntu/Linux distribution, or an emulator on Windows like Cygwin.

1) Run ssh-keygen

abdullah@desktop:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/abdullah/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/abdullah/.ssh/id_rsa.
Your public key has been saved in /home/abdullah/.ssh/id_rsa.pub.
The key fingerprint is:
06:23:fc:34:0f:12:40:b2:5e:7c:41:eb:4f:a2:ab:24 abdullah@desktop
The key's randomart image is:

Randomart image

2) Run ssh-copy-id <username>@<server-name>

abdullah@desktop:~$ ssh-copy-id login@myserver.com
login@myserver.com's password: 
Now try logging into the machine, with "ssh 'login@myserver.com'", and check in:

 ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

3) Login to your server using ssh

abdullah@desktop:~$ ssh 'login@myserver.com'
Welcome to MyServer.com!
Last login: Sun Sep 25 23:22:21 2011 from 209.85.175.105
login@myserver.com:~# 

That’s all!

If you want a quick shortcut in the GUI, you could add a Custom Application Launcher to the panel with the ssh login command, as shown below:

Launcher Properties

Clicking the panel icon will directly open the terminal at the server with you logged in.

Note that this will also automate the login for SFTP, so you won’t need to type in your passwords there anymore too!



Comments

while trying for key exchange i got following message
" 'umask' is not recognized as an internal or external command,
operable program or batch file.
The system cannot find the path specified."
I guess the sftp server I am trying to access is windows based.

Can anybody help me to automate the login to it?

By pankaj

Hi Pankaj,

You'll need to figure out a way of adding your public key to server so that it can use it for authentication. For example, page 9 in this document talks about how to do it with the freeSSHd Windows software.

If you're stuck, do feel free to reply back with more details on your setup.

By Abdullah Chougle

Add new comment