Background
In this post we will see how to do a SSH key based authentication where you do not need to enter your password. For demo purpose I am going to start a SSH server on my Linux Ubuntu machine and then connect to it from my same linux machine without password.
Starting SSH server
First lets install openssh server.
- sudo apt-get install openssh-server
Now lets take a backup of config file so that we have a good config too look at later (in case we mess things up ;) ) -
Execute the following commands -
- sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.factory-defaults
- sudo chmod a-w /etc/ssh/sshd_config.factory-defaults
- sudo gedit /etc/ssh/sshd_config
NOTE : sshd_config is the configuration file for the OpenSSH server. ssh_config is the configuration file for the OpenSSH client. Make sure not to get them mixed up.
Now simply restart ssh server -
- sudo restart ssh
Sure you can do the same from any other machine using password
But in this we want to do this without password -
Configuring ssh connection without Password
You need to execute following commands -
- ssh-keygen
- ssh-copy-id -i ~/.ssh/id_rsa.pub aniket@localhost
As you can see post copying the public key to servers authorized keys you no longer need password to connect to your SSH server.
192.168.x.x is a local address on the lan not a wan address.
ReplyDeleteYou have to open a port 22 in router then what happens?