December 04, 2024, 11:36:08 AM

News : LinuxSolved.com Linux Help Community Forum..


Author Topic: Regular user Can't SSH using public Key but root can  (Read 17560 times)

Offline Saahib

  • Linux Noob !
  • *
  • Posts: 4
Regular user Can't SSH using public Key but root can
« on: May 18, 2020, 12:19:59 AM »
Hi,

This is driving me nuts from few days. I have server where I can login as root user through SSH using public key authentication. I then added new user with SSH.

Added new user :
Code: [Select]
adduser  -m newUser
Created password for it :
Code: [Select]
passwd newUser
Added .ssh/authorized_keys with client machines public key (which is I am already using to log into as root from this client)
Code: [Select]
echo "key here from client" >> /home/newUser/.ssh/authorized_keys
I have double checked, triple checked.  Same key works for root login but not for new user.

I tried ssh to ssh with -v ,then last few lines:

Code: [Select]
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: password
newUser@server.com's password:

It looks like its my ssh server is not able read publickey ? I can login using password though.

I have done this in past many times, for root and normal user but this time its not working, driving me nuts...

I am sure I am making some tiny mistake.. but where it is ?

Offline dalek

  • LST CareTaker
  • Crescent
  • *****
  • Posts: 243
Re: Regular user Can't SSH using public Key but root can
« Reply #1 on: May 18, 2020, 01:46:12 AM »
I would check permissions of the key files and also check to be sure the user is a member of the correct groups.  I haven't used ssh in ages but seem to recall it requiring being a member of a certain group.  Given your output, it seems to be trying so that leads me to believe it is a permission issue with the key files.  I'd suggest setting it to be readable by all but only writable by root.  It may be that it can see the file exists but is unable to read the contents of the file. 

Hope that helps.

Offline Saahib

  • Linux Noob !
  • *
  • Posts: 4
Re: Regular user Can't SSH using public Key but root can
« Reply #2 on: May 18, 2020, 08:16:11 PM »
Oh man, it was driving from many days, it was indeed permission problem . I had checked actually , permission were 644 and ownership was also correct (owned by the user) however.

Looking around I found that we need following permission, I am sharing here for future reference:
Code: [Select]
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Problem was that I was comparing permission with root .ssh and its content but that doesn't work for regular user.