SSH ( Secure Shell ) is widely used for remote login to Linux servers. When we login to a remote system using ssh, it prompts for password and then only allow us to login to server. Some times we need to configure applications or scripts (mostly shell script) to automate some tasks to do after ssh to remote system. But if we do not have configured key-based ssh, script will prompt for password on each run which we need to manually enter. To solve this problem, we have alternative to use public/private key concept. In which remote server allows other system to ssh on basis of key.
This article will help you to Setup SSH without password in Linux Systems suing ssh ( rsa/dsa ) key pair.
Step 1: Generate SSH Key Pair
Firstly you would required to generate a key pair (RSA or DSA), you can specify option rsa or dsa key using ‘t’ command line switch. If we do not pass -t parameter, it will create rsa key by default.
# ssh-keygen -t rsa
The above command will create two files in ~/.ssh directory as followings.
- ~/.ssh/id_rsa [private key]
- ~/.ssh/id_rsa.pub [public key]
Step 2: Copy Public Key to Remote System
Lets copy our public key of our system to remote computers ~/.ssh/authorized_keys key file. We can do this manually or using ssh-copy-id command line tool.
# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.1.103
21 [email protected]'s password: Now try logging into the machine, with "ssh '192.168.1.103'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting.
Its will prompt for password of remote system. Enter remote machine password and press enter.
Step 3: Verify SSH without Password
Now as we have all done, simply try to ssh to remote system. You will login to remote system without entering password.
# ssh [email protected]
Above command will not prompt for password to login. In any case if ssh command prompts for password, it means your setup is not configured properly and try again all the steps again.
Thanks for reading this article, I hope it will help you.