Table of Contents

How to ssh without password using ssh-key-gen and ssh-copy-id

let say we want to go from server1 to server2

Server1 is current server and server2 is where we want to login

Create the ssh directory on both the servers if they are not already existing.

on current Server do mkdir ~/.ssh

On remote server do...

ssh root@server2_ip mkdir -p ~/.ssh

Now generate the ssh key using the following command, dont set any paraphrase...

ssh-keygen -t rsa

Upload generated public keys to ~/.ssh/ directory to server2 using scp command

scp -p ~/.ssh/ [email protected]_ip:~/.ssh/

Now run the following command to authenticate

ssh root@server2_ip "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"

Now try logging to server2_ip, you would not need a password.

Install Using ssh-copy-id

There is easier way to using ssh-copy-id...

Install the following utility

yum install ssh-copy-id

we will use the utility ssh-copy-id to authenticate

ssh-copy-id -i ~/.ssh/ [email protected]_ip

Now try logging in, you would not need a password

Related Posts