sometimes I always try to remote to my other computer using ssh, because I always try to remote to my other computer and it always ask for password. so I try to ssh to my other computer without it’s trying to ask for password using the following rule.

so first thing you have to do is to open your terminal and run this.

kamsis@ian-desktop:~$ sudo cat /etc/hosts
[sudo] password for kamsis:
127.0.0.1    localhost
10.14.2.109    yucie-desktop
10.14.2.104    ian-desktop

the above result for /etc/hosts should be the same as in your remote computer, so the content of /etc/hosts should be the same.

and then type this in your terminal
kamsis@yucie-desktop:~$ ssh-keygen -t rsa

it will generate a key and it will ask for a password and you have to remember this password.

and now do the same thing as above on your other computer

after that go to .ssh directory and do this
kamsis@yucie-desktop:~$ ls -l .ssh
total 24
-rw——- 1 kamsis kamsis 1198 2009-05-15 20:55 authorized_keys
-rw——- 1 kamsis kamsis 1743 2009-06-13 22:45 id_rsa
-rw-r–r– 1 kamsis kamsis  630 2009-05-15 20:37 id_rsa.keystore
-rw-r–r– 1 kamsis kamsis  402 2009-06-13 22:45 id_rsa.pub
-rw-r–r– 1 kamsis kamsis 5070 2009-05-15 20:39 known_hosts

you will see that id_rsa.pub has been created, you will notice that id_rsa.pub is a public key and id_rsa is a private key. now copy id_rsa.pub to authorized_keys using this command

kamsis@yucie-desktop:~/.ssh$ cp id_rsa.pub authorized_keys

and you should also do this to your other computer. after that change the file permission using this command

kamsis@yucie-desktop:~/.ssh$ chmod 600 authorized_keys
and you should also do this to your other computer

after that you need to copy id_rsa.pub of other computer and add it to your authorized_keys file. I use scp to do this.

kamsis@yucie-desktop:~/.ssh$ scp kamsis@10.14.2.104:/home/kamsis/.ssh/id_rsa.pub ~

it will ask for the password and you have to entered it. after that do the same thing in your other computer.
after you have the id_rsa.pub of another computer you have to add the content of id_rsa.pub to your authorized_keys. and you should also do this to your another computer. after you have done adding the content of id_rsa.pub to authorized_keys, now try to ssh to your another computer and it won’t ask for the password anymore. :-)  

now try it for yourself. :-)

One Response to “how to ssh to another computer without asking for password”

  1. What a gem. It’s a real shame more people haven’t heard about this site, this article had just what I needed today XD

Leave a Reply