SSH keys

SSH Keying through Linux, Mac OS X

SSH keys are fairly simple to setup and can be done so even simpler when using a native terminal application, such as the terminal in OSX. Here's how!
In terminal, type the following command:

ssh-keygen -t dsa

This will ask you a few questions, the defaults for which are just fine, no passcode is necessary. This will generate a key in the ~/.ssh/ directory. Now we just need to get that file up to the server.
You can do this using scp or rsync, I'll give rsync as an example here.

rsync -av -e "ssh" ~/.ssh/id_dsa.pub root@IP_address:.ssh/authorized_keys

In the event your server uses a non-standard port for ssh, you can specify this inside the quotes around ssh, an example for port 2222 is below.

rsync -av -e "ssh -p 2222" ~/.ssh/id_dsa.pub root@ip.add.ress.here:.ssh/authorized_keys

Once running this command you will be prompted for your root password as rsync creates an SSH connection to transfer the file to your server. Once the password is entered, the file will be synced up to the server.
Now we want to ensure that all is well on the recipient server. SSH into your server and run the following commands.

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown root. ~/.ssh/authorized_keys

That's it! You should be all set! Now to access your server you need only do the following:

ssh root@domain.com

The server should automatically accept your key and push you into the root shell.

How to disable password authentication

Once this has all been configured, you can add some extra security to your server by disabling password authentication for SSH. (Note that if you do lose your private key, this will make the server inaccessible.)
To disable this setting, you can do the following:

nano /etc/ssh/sshd_config

In this file, set the following settings to the following values. If these settings are already in the file, set them to "no" rather than add new lines.

ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

Once this is done, restart the SSH daemon to apply the settings.

/etc/init.d/sshd restart

Its done. :)

Comments

  1. Hi Avi,


    For Mac 10.8, X11 package is not coming inbuilt. So needed to install it manually, or else what ever we do, X term will not work. Thnx for the post.

    ReplyDelete

Post a Comment

Popular posts from this blog

SVN: File remains in conflict

HowTo: Enable extended logging for exim

12 tweakings for WHM/cPanel to speed up WordPress