0

I am setting up a user account to log into the server through SSH. The user name is 'sam'

sudo useradd sam

This created a /home/sam directory. I created a .ssh directory and wrote a public key to the authorized_keys file within this directory. I was able to log into the system using Putty and FileZilla (using the corresponding private key, of course)

However now I do this:

sudo usermod -d  some_other_directory  sam

Then I created .ssh within the above new home directory and created the authorized_keys file....all with appropriate permissions and ownerships (sam owner and sam group). I am not able to log into the system at all now....The second I change the home directory back to /home/sam I am again able to log in.....any ideas about what I am doing wrong here?

  • is ownship OK along the path from / to some_other_directory ? – Archemar Nov 19 '16 at 10:46
  • 'sam' is the owner of 'some_other_directory'...but this directory is deep into the system and the directories above it are owned by other users. – Nikster2014 Nov 19 '16 at 22:34
  • you need r-x access for sam all along the path from / – Archemar Nov 19 '16 at 22:40
  • And how do I do that :) The new home directory for the user is /var/www/html/websitename/html – Nikster2014 Nov 20 '16 at 1:40
  • And how do I do that? :) The 'some_other_directory' is /var/www/html/websitename/html – Nikster2014 Nov 20 '16 at 1:43
0

Check /var/log/auth.log or /var/log/secure or other similar file depends on your system. There is a chance you will find some records like:

sshd[32458]: Authentication refused: bad ownership or modes for directory some_other_directory

And after you chould check ownerships and modes for that folder and fix it accoridngly: your home directory and .ssh must not have group and others write permissions.

  • I did chmod 700 for the .ssh directory and chmod 600 for the authorized_keys directory. What permissions do I need to set for the user's home directory? Thanks! – Nikster2014 Nov 19 '16 at 19:37
  • Home directory should have 700, 751 or 755. Personaly I prefer 751, you could also try that mode. – Fedor Dikarev Nov 19 '16 at 20:13
  • Didn't work! I have all the permissions set up correctly. Putty is saying 'server refused our key' even though the authorized key file was copied from /home/sam (which was working just fine) – Nikster2014 Nov 19 '16 at 22:35
  • Please share permissions, last errors from ssh and number of lines on authorized_keys file. Next commands may help you: whoami; ls -ld some_other_directory some_other_directory/.ssh some_other_directory/.ssh/authorized_keys; wc -l some_other_directory/.ssh/authorized_keys; egrep -c -w 'ssh-[rd]sa' some_other_directory/.ssh/authorized_keys; sudo tail /var/log/secure. And you could add this information to your main post so it will be easier to read and understand your problem. – Fedor Dikarev Nov 20 '16 at 9:07
0

It's possible that you have Selinuxenabled and it blocks access for authorized_keys outside /home folder. Here is Centos forum thread how to fix that issue.

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.