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.
