Ubuntu – SSH broken after homedir permissions and hostname change on EC2-hosted Ubuntu

amazon ec2amazon-web-servicessshUbuntuubuntu-12.04

I changed my instance's hostname using the hostname utility and then set it in /etc/hostname so that the new name survives reboot.

My main motivation was for differentiating between instances at the prompt using the \h
format in PS1.

EDIT
I also changed permissions on my home directory. I made my home directory group writeable.

Now I can no longer SSH into the machine. The short of it is the error Permission denied (publickey). Running ssh -v, the more verbose output is:

debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/dmitry/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/dmitry/.ssh/ec2key.pem
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

Should I have done something after changing the hostname? Now I can't get into the instance! 🙁

Best Answer

Thankfully the root mount was running on an EBS volume. So, I was able to debug this issue by stopping the instance and attaching the EBS volume to another instance I had running. I then examined /var/log/auth.log, which provided the useful information ssh -v was not providing. I noticed:

Nov 26 02:55:39 myhost sshd[1746]: Authentication refused: bad ownership or modes for directory /home/myuser

Indeed, SSH was not happy that I had given group write perms to my home directory, while StrictModes was set to yes in /etc/ssh/sshd_config.

More information on this issue can found at http://recursive-design.com/blog/2010/09/14/ssh-authentication-refused/ or by searching the Web for SSH StrictModes or Authentication refused: bad ownership or modes for directory.