Safe and Easy Terminal Login with SSH Config File

Managing so many WordPress websites, dealing with Terminal & command lines is inevitable. I use Mac OS X, so Terminal app and SSH command are the tools get me connected with remote machines occasionally. Although Coda 2 is my main code editor, FTP client & Terminal app, there is time I like to pop up the simple Terminal app, and use few command lines for a quick checkup.

Instead of using standard SSH command line like this:

ssh username@server.domain.com

and then be asked for password every time. I find using private SSH key is much easier and safer without worrying about password. Because I managed so many websites, and there is no way I can remember those lengthy weird passwords without copy & pasting from some secret documents, which slows down my work.

In Mac OS X, we can use SSH Client Configuration file to achieve this. First, we start the config file in editor:

vi ~/.ssh/config

Add the following settings for the site:

Host site-alias
Hostname server.domain.com
User username
IdentityFile ~/.ssh/id_dsa

This is to tell SSH client to login to server.domain.com as user “username”, using private key file id_dsa as authentication. id_dsa is the private SSH key file obtained from CPanel @ server.domain.com. (If you want to know how to get a private SSH key file, please refer to “How to Setup SFTP Connection with Private SSH Key in Coda 2“).

With this configuration, I can use simple command like this:

ssh site-alias

to connect to server.domain.com without typing in user name & password.

For the first time using the private key, system will ask you for the key password.

private-ssh-key-password

Choose “Remember password in my keychain” if you don’t want to be asked for password every time.

 

Comments are closed.

Post Navigation