How to SSH to a host without login

Here are 2 easy steps to ssh into a host without login:

Scenario:

Remote host IP: 192.168.1.25
Remote host Username: root

Note: We need OpenSSH to be installed on the remote host for this to work.

  1. From your PC run the following command:
root@mehrdust# ssh-keygen -t rsa

now a file named authorized_keys should have been created on you .ssh folder.

# ls -l /root/.ssh
-rw------- 1 root root 1679 2011-11-09 10:55 id_rsa
-rw-r--r-- 1 root root  402 2011-11-09 10:55 id_rsa.pub

2. Run the following command to copy this key to the remote host:

# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.25
The authenticity of host '192.168.1.25 (192.168.1.25)' can't be established.
RSA key fingerprint is ef:23:31:87:a9:fa:cc:e7:fd:d2:5a:1a:d9:e2:35:4a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.25' (RSA) to the list of known hosts.
root@192.168.1.25's password:
Now try logging into the machine, with "ssh 'root@192.168.1.25'", and check in:

 .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

At this point the id_rsa.pub is copied to the remote host as authorized_keys. After this you can ssh root@192.168.1.25 and login without being prompt for password.

You may also like