289

I am trying to connect to a Linode (running Ubuntu 12.04 LTS) from my local machine (also running Ubuntu 12.04 LTS)

I have created a private and public key on my local machine and copied my public key to my Linode's authorized_keys file. However, whenever I try to ssh to my Linode I get the error message Permission denied (publickey).

It's not a problem with how ssh is set up on my Linode because I can ssh to it from my Windows machine using key authentication.

In my .ssh directory on my local Ubuntu machine, I have my id_rsa and id_rsa.pub files. Do I need to create an authorized_keys file on my local machine?

EDIT: This is what I get when I run ssh -vvv -i id_rsa [youruser]@[yourLinode]:

debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).
Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83
Pattle
  • 3,029
  • 3
  • 15
  • 7
  • 9
  • What do the logs on the SSH server say about the time you have this error on the client? (/var/log/auth.log) 2) How did you transfer the public key to the server? Always use ssh-copy-id to be sure about permissions. Your home directory, the .ssh directory and the authorized_keys file have strict permission requirements. (see manpage of sshd (8) on ~/.ssh/authorized_keys). 3) Did you generate a new keypair on Ubuntu? In case you reused the key from Windows - you'll have to convert it to OpenSSH format first.
  • – gertvdijk Jun 23 '13 at 01:13
  • 2
    The command should have been ssh -vvv -i .ssh/id_rsa .... (note the path to id_rsa!) - please replace - the old log only shows that "we" had no pubKey to send. – guntbert Jun 23 '13 at 11:22
  • @guntbert I missed out the .ssh because I was already in the .ssh directory. I also tried it with .ssh/id_rsa but I got the same result – Pattle Jun 23 '13 at 11:30
  • I see, so I misread - Please answer the questions from @gertvdijk. – guntbert Jun 23 '13 at 11:40
  • 2
    I had same problem. I could log on as root but not as new_user. If you can access your server as root or a sudo user you can watch the ssh auth log via "tail -f /var/log/auth.log". in my case the problem was the new_user was configured with an invalid shell. "user new_user not allowed because shell /bin/ is not executable". – Bryan Feb 16 '22 at 16:41
  • 2
    (not enough reputation to post as an answer) More recently, this can also happen due to the SHA-1 signature in RSA keys becoming deprecated. Running ssh -vvv will report "no mutual signature algorithm" if this is the case. To fix, either update your ssh server to support rsa-sha2, or regen your key with ssh-keygen -t ed25519, or pass -o PubkeyAcceptedKeyTypes=+ssh-rsa to the ssh client. – Sir Athos Apr 26 '23 at 09:26
  • I had this today with a new user account I had added - the keys were fine and all were installed correctly. On checking the /var/log/auth.log, I could see that the connection was being refused becasue the user account was not in the AllowUsers list in the server's – ChumKui Aug 10 '23 at 13:43
  • meant to say the server's SSH config file (/etc/ssh/sshd_config). It is good practice to lock down SSH in this way so only those user accounts that abolsutely need to SSH in, can do. – ChumKui Aug 10 '23 at 13:50