Setup Automatic Login for SSH in WHM/CPanel with OSX
If you run any number of servers and have to login many times a day it can quickly become tiresome if you dont’t want to have to type in your password every time and you don’t want to store this anywhere in the finder or the keychain utility of OSX.
Create Your Public Key & Publishing It
The gist to automatic login is that you will generate a public key using ssh-keygen, then copy this to the remote server and append it to the authorized keys file for the user. Thereafter, everytime you go to login, the server will accept your loginw ithout a password being required because you can identify your computer as being the owner of an authorized key.
The steps to doing this are as follows:
- # ssh-keygen -t dsa
- // to generate the public key
- # chmod 700 ~/.ssh
- // to ensure your .ssh directory has the right permissions
- # scp ~/.ssh/id_dsa.pub remoteuser@remoteserver.com:
- // to copy the key to the remote user dir
- # cat id_dsa.pub >> .ssh/authorized_keys
- // to append the contents of the public key to the right location on the remote server
- # rm ~/id_dsa.pub
- // to remove the public key from the remote user’s home directory
Now when you have logged out and attempt to login again using remoteuser@remoteserver.com you will no longer be prompted for a password.
Disabling Automatic Login for SSH
This might sound liek nirvana as a sys admin, but at some point, for security or otherwise you may wish to disable automatic login. To do this edit:
- # /etc/ssh/sshd_config,
Uncommenting the following line:
- # PubkeyAuthentication yes
And of course changing “yes” to “no”, followed by a restart of the SSH server.
Conclusion: Great for Automatic Scripting
As you can see it is nice and simple to get started and to maintain for use with unmanned and unattended scripts that perform whatever function on your servers, and of course removing the need to hold any password on your computer, for security reasons or otherwise, though automatic-login poses a security risk in itself.
















