Support Tutorials

Find help without having to contact us.

Securing SSH on your Linux Dedicated Server

  1. Home
  2. Dedicated Servers
  3. General Info
  4. Securing SSH on your Linux Dedicated Server

Secure SSH using Public Key Authentication Public key authentication is a more secure way of authenticating via SSH to your server and if all password-based authentication methods are disabled, it can prevent any brute force SSH attacks. Generating a Key First we need to generate a key that will be used to access your server. In a Linux environment this utility is normally built in, Windows users can download this tool for generating keys. In Linux you can run the following commands from your bash prompt.

client$ mkdir -p ~/.ssh client$ chmod 700 ~/.ssh client$ ssh-keygen -q -f ~/.ssh/id_rsa -t rsa Enter passphrase (empty for no passphrase):

Do not use your account password, nor an empty passphrase. The passphrase should also be at least 8 characters long. Distributing a key The public portion of the RSA key pair must be copied to your server and appended to ~/.ssh/authorized_keys to enable access. If you are running Linux, the public key information to be copied should be located in the ~/.ssh/ file on your PC. To copy the public key to your server run:

client$ scp ~/.ssh/ [email protected]:

server$ mkdir ~/.sshserver$ chmod 700 ~/.sshserver$ cat ~/ >> ~/.ssh/authorized_keysserver$ chmod 600 ~/.ssh/authorized_keysserver$ rm ~/

Disabling Password Authentication

Once you have loaded your key onto the server and have tested that you are able to login using the key, you can then edit your ssh configuration on the server to disable standard password authentication. As root, edit the file /etc/ssh/sshd_config on your server. Ensure the following lines exist and edit as follows

RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys

PasswordAuthentication noChallengeResponseAuthentication noUsePAM no Save the file, and restart sshd

/etc/init.d/sshd restart

Your server is now secure from brute force ssh attacks.

Was this article helpful?

Related Articles