Just make sure that you have followed the following procedure:
On Machine A
open a terminal and enter the commands as follows:
root@aneesh-pc:~# id
Just to make sure that we are root.
If the above command output something like below we are root else switch to root using the su
command
uid=0(root) gid=0(root) groups=0(root)
1) Create the keys.
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
49:7d:30:7d:67:db:58:51:42:75:78:9c:06:e1:0c:8d root@aneesh-pc
The key's randomart image is:
+--[ RSA 2048]----+
| ooo+==B|
| . E=.o+B|
| . . .+.*o|
| . . . ...|
| S |
| |
| |
| |
| |
+-----------------+
I haven't used any passphrase. If you need one you can use it.
2) Copy the public key in to machine B's .ssh/authorized_keys
file
root@aneesh-pc:~# ssh-copy-id -i /root/.ssh/id_rsa.pub root@mylap
root@mylap's password:
Now try logging into the machine, with ssh 'root@mylap'
, and check in:
~/.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
Replace mylap with the hostname or ip of the machine you want to login (i.e. machine B)
3) Login to B without password
root@aneesh-pc:~# ssh root@mylap
Warning: Permanently added 'mylap,192.168.1.200' (RSA) to the list of known hosts.
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-8-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Wed Jul 27 15:23:58 2011 from streaming-desktop.local
aneesh@mylap:~$
On Machine B
4) Create the keys to login back to Machine A
root@mylap:~# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
35:9f:e7:81:ed:02:f9:fd:ad:ef:08:c6:4e:19:76:b1 root@streaming-desktop
The key's randomart image is:
+--[ RSA 2048]----+
| |
| |
| o . |
| . + + o |
| S o * E |
| = O . |
| O + |
| + o o.|
| . o+=|
+-----------------+
5) Copy the public key in to machine A's .ssh/authorized_keys
file
root@mylap:~# ssh-copy-id -i /root/.ssh/id_rsa.pub root@aneesh-pc
Warning: Permanently added 'aneesh-pc,192.168.1.20' (RSA) to the list of known hosts.
root@aneesh-pc's password:
Now try logging into the machine, with ssh 'root@aneesh-pc'
, and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
6) Login to A without password
ssh root@aneesh-pc
Warning: Permanently added 'aneesh-pc,192.168.1.20' (RSA) to the list of known hosts.
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.38-8-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Tue Jul 26 18:52:55 2011 from 192.168.1.116
If you are able to complete these steps You are done. Now you have two machines with ssh-key (public-key) enabled login.
First of all, You NEVER upload your private keys to anywhere.
Let's get this right.
- Server is running ssh_d service on a different port (12xx)
- You forwarded 12xx port on your router to the server.
- You can connect if you are on the same network using
ssh -p 12xx user@server.ip
- You can connect if you are on another network using
ssh -p 12xx user@noip.address
- Both connections you are using the same origin box (i assume laptop)
Please verify this so we can help you troubleshoot your issue.
Just to give you a heads up since you claimed this is your first time playing with ssh.
You need to use the "@" to connect if you are running locally with a different username than the one you want to use on the server.
This is:
usernameA [laptop] ---> ssh ---> usernameA [server]
In that case, you would use:
ssh -p 12xx youraddres.no-ip
If you use different usernames, then you have to specify it by using "@". So if this is the case:
usernameA [laptop] ---> ssh ---> usernameB [server]
You should use:
ssh -p 12xx usernameB@youraddres.no-ip
Best Answer
First of all, I suggest, if you can, to remove+purge, then reinstall openssh-client/server on the three machines, and remove each ~/.ssh, so that you start from a clean situation.
Next, follow this ubuntu wiki page that treats more specifically of ssh keys configuration.
Last, keep in mind the following issue: from debian ssh wiki: