10 Jan 2009
How to save SSH passwords in Terminal (on linux Ubuntu)
This simple tutorial explains you how to save a SSH password using one simple alias.
- Open the terminal and edit with your favourite text editor (vim in this case) the file .bashrc:
vim ~/.bashrc
- Add the new alias to the file (obviously change “user” with your SSH username and “host.com” with your SSH address host):
alias s='ssh -2 -p 22 user@host.com'
This means that every time you will type “s” in your terminal, that line will be executed. You can change the letter “s” to another one if you prefer.
The “-2” option is used to force SSH2 connections instead of simple SSH.
The “-p 22” option is used to connect via SSH to the port 22 (usually the default port). -
Run these commands one time only (you can copy and paste each one) in the following order; remember to change “user” and “host” with your data:
# generate pub and priv keys, leave the passphrase empty # (simply press ENTER when asked for it) ssh-keygen #copy the pub key to the remote computer #(change port number if different from the usual 22) #change "user" to your user name #change "host" to your domain name scp -P 22 ~/.ssh/id_rsa.pub user@host:~/ #log on to the remote computer ssh -p 22 user@host #create the .ssh directory in the root login directory, if it doesn't already exist mkdir .ssh #append key to file cat id_rsa.pub >> ~/.ssh/authorized_keys #delete the public key file, no longer needed rm -f id_rsa.pub #log off the remote server exit #logon to the remote server, without password prompt ssh -2 -p 22 user@host
- That’s it!
Simply type “s” in your terminal and this will instantly launch the ssh connection without asking your password anymore!
Thanks to Alessio and sniptools.
Note: I used the .bashrc file instead of .profile file (as suggested from sniptools) to save the alias however it did not work.
Thanks,
it worked just fine!
Ferran
January 27th, 2009 at 13:50:40permalink
Very good! ^^
MDT
January 27th, 2009 at 13:53:44permalink
Appreciating the hard work you put into your blog and in depth information you provide. It’s awesome to come across a blog every once in a while that isn’t the same outdated rehashed information. Fantastic read! I’ve bookmarked your site and I’m adding your RSS feeds to my Google account.
Reynaldo Hultz
February 16th, 2011 at 06:29:46permalink
Thanks Reynaldo!
Unfortunately I did not update the blog very often lately…
Ciao!
MDT
February 19th, 2011 at 19:23:43permalink
Nice it worked
Gubs
March 28th, 2013 at 20:32:46permalink