Ubuntu

How To Install & Generate An SSH Keys And Disable Password Authentication On Ubuntu

Posted by Weston Ganger on July 27, 2015

When using SSH to access your server it can get annoying to enter the password every time. Well not only that but password authentication poses a security risk as well because you may be vulnerable to brute force attacks.

Here we will setup SSH keys and disable password authentication.

First install ssh server on your server


sudo apt-get install openssh-server

Now on your client machine:


# generate ssh keys
ssh-keygen -t rsa

# Append your public key to the server .ssh/id_rsa -> .ssh/authorized_keys
ssh-copy-id user@domain.com
# or to an ip
ssh-copy-id user@192.168.1.4

# connect to the server
ssh user@domain.com

As you can see you were no longer required to enter a password to SSH in to your server because you are now using the SSH keys.

Next we want to disable password SSH. This is a good idea because it means people can’t perform brute force attacks against your server.

Edit the SSH config on the server /etc/ssh/sshd_config


# /etc/ssh/sshd_config

# make sure the following entries are set to yes and are uncommented
RSAAuthentication yes
PubkeyAuthentication yes

# the following entries need to be set to no and are uncommented
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no

Now lets test this


# reload the ssh configuration
sudo service ssh reload

# disconnect from server
exit

# try connecting without the need of a password, you may need to give a password to access your private key file but not for the ssh program.
ssh user@domain.com

# try to connect to server with ssh key file auth disabled
ssh user@domain.com -o PubkeyAuthentication=no
# this should give you a permission denied message

There you go you should have it all setup with no more need of passwords.

One handy tip if you did not know is that you can copy your .ssh folder to all of your machines and they can share the ssh keys. You will just have to restart the ssh-agent after copying the files. But that way your can save them and not have to manage a million ssh keys.


Related External Links:


Posted in Linux and Tagged with linux ubuntu ssh 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts