Linux CentOS 5 SSH User Permission Denied

7,242

Solution 1

you said you have root access. ssh to the box as root and see what exactly is causing it. check the master log file /var/log/messages.

keep this command tail -f /var/log/messages running in a terminal and ssh to the server as a normal user. Look at the entries in log file.

Solution 2

It sounds like you might have changed the permissions of your ~/.ssh directory and/or your ~/.ssh/authorized_keys file. Or possibly made your home dir group or world writable.

~/.ssh should be 700 (drwx------) and ~/.ssh/authorized_keys should be 600 (-rw-------).

Your private key file(s) in ~/.ssh (id_rsa, id_dsa, etc) should also be 600. The perms on the public key files (id_rsa.pub, id_dsa.pub, etc) are less strict - they can be world-readable.

All these files and directories should be owned by your user.

If your home directory is world-writable and StrictModes is set in sshd_config (default is "yes"), then sshd will not trust anything underneath your home directory (including ~/.ssh and everything in it) because a world-writable hoome dir means any user on the system could have created or modified the files.

I'm not sure how sshd on Centos handles group-writable home dirs, but the same may apply if your home dir is group-writable - any user in the group may have created/altered the ~/.ssh files. (IIRC Debian's sshd is configured to allow group-writable home dirs because Debian's adduser traditionally creates a group for each user which only the user is a member of)

Share:
7,242

Related videos on Youtube

Angel Wong
Author by

Angel Wong

Updated on September 18, 2022

Comments

  • Angel Wong
    Angel Wong over 1 year

    Today when I try to SSH into my server, I get a permission denied message (same for sftp). It used to work well before, I didn't change any server settings, except I was trying to modify a few folders chown permission.

    Root user can ssh/sftp without problem.

    (For root user, there is no .ssh/authorized_keys file, only a .ssh/known_hosts file. For normal user home folder does not have a .ssh folder).

  • Angel Wong
    Angel Wong over 11 years
    Accepted password for USER from 127.0.0.1 port 51550 ssh2 pam_unix(sshd:session): session opened for user USER by (uid=0). that's the log file message. but in the ssh terminal, the error message is "-bash: /dev/null: Permission denied" please advice if there is anything i can try. thx
  • Angel Wong
    Angel Wong over 11 years
    as said, there is no authorized_keys file in both root and normal user account. also, .ssh folder does not exist in user home directly. .ssh folder only in root directly, and permission is 600. please advice if there is any other thing i can try. thx a lot
  • Alessio
    Alessio over 11 years
    from your answer to fayadlami, it sounds like you're logging in successfully. i'll comment more under f's answer.
  • Alessio
    Alessio over 11 years
    check your .profile, .bashrc, and/or .bash_profile scripts. that sounds like there might be a line like exec /dev/null (possibly intended as something like exec 2>/dev/null). Also, as root, check the perms on /dev/null, it should be owned by root:root, perms 666 (crw-rw-rw).
  • Alessio
    Alessio over 11 years
    actually, ignore what i said about your login scripts, it sounds like it's a permissions problem with /dev/null. make sure perms are 666. lmgtfy.com/?q=%22bash%3A+%2Fdev%2Fnull%3A+Permission+denied%‌​22
  • Angel Wong
    Angel Wong over 11 years
    thx Craig. works like a charm