I have a server that I log in with SSH and I use key based authentication. I now set up a second server and I want to use the same key for login.

Thus, I copied the file ~/.ssh/authorized_key from the old server to the new server.

On the Windows client, I cloned the SSH configuration in Putty and only exchanged the IP address of the server.

This does not seem to be sufficient. The error message of Putty on Windows is

PuTTY Fatal Error

Disconnected: No supported authentication methods available (server sent: publickey)

And on the SSH console I see

Server refused our key

The server configuration is

AllowGroups sshlogin
Port 2233
PermitRootLogin no
PasswordAuthentication no
ChallengeResponseAuthentication no

Even if I copy the other key files (id_rsa and id_rsa.pub), I still can't login.

# ls -l
total 12
-rw------- 1 root root  411 Jan 14 22:39 authorized_keys
-rw------- 1 root root 1792 Jan 14 22:53 id_rsa
-rw------- 1 root root  411 Jan 14 22:39 id_rsa.pub

Which files do I need to copy to get an identical SSH login on both machines?

I have tried:


It turned out to be a permission problem:

-rw------- 1 root root  411 Jan 14 22:39 authorized_keys

should not be accessible by root:root but by the user who shall log in. So the following fixed the issue:

chown myuser:myuser authorized_keys
rm id_rsa
rm id_rsa.pub
service sshd restart
  • also, the parent directory (normally /home/USER) may only be writetable for the owner (755). – Stefan Jan 14 '18 at 22:26
  • In the future use ssh-copy-id , it copies your public key (rsa.pub) to the server (~/.ssh/authorized_keys) and sets proper permissions. – Panther Jan 14 '18 at 23:44
  • @Panther: thanks for the hint. So I upload rsa.pub, then use ssh-copy-id and then delete rsa.pub? I don't think the tool can copy something to the server, because the source is my KeePass file on Windows, where ssh-copy-id does not have access to. – Thomas Weller Jan 15 '18 at 9:16
  • From the client you run ssh-copy-id user@server and everything is taken care of for you. You can keep or delete the rsa.pub on the client, but I usually keep it. You need the rsa to log in with. – Panther Jan 15 '18 at 10:27
  • @Panther: there's no such tool on Windows, so I would need to replicate its behavior. Basically that's what I did (without knowing it) – Thomas Weller Jan 15 '18 at 12:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.