Question

I had ssh installed and working. I ran sudo chmod -R 777 /var and it stopped working. I changed permissions with sudo chmod -R 700 /var but that didn't make it work again.

When I do ssh -v localhost I get this output:

rajat@ubuntu:/$ ssh -v localhost
OpenSSH_5.8p1 Debian-1ubuntu3, OpenSSL 0.9.8o 01 Jun 2010
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/rajat/.ssh/id_rsa type -1
debug1: identity file /home/rajat/.ssh/id_rsa-cert type -1
debug1: identity file /home/rajat/.ssh/id_dsa type -1
debug1: identity file /home/rajat/.ssh/id_dsa-cert type -1
debug1: identity file /home/rajat/.ssh/id_ecdsa type -1
debug1: identity file /home/rajat/.ssh/id_ecdsa-cert type -1
ssh_exchange_identification: Connection closed by remote host
rajat@ubuntu:/$ 
Was it helpful?

Solution

OpenSSH is very picky when it comes to file and directory permissions and ownership. The only directory under /var that it touches, at least on RHEL/CentOS, is the /var/empty/sshd directory, which it does a chroot to if UsePrivilegeSeparation is set to yes.

Set this in your sshd_config file:

UsePrivilegeSeparation no

And restart sshd, and see if it works. If that does it, it's likely the permissions/ownership on /var/empty/sshd that's causing the problem.

OTHER TIPS

If anyone runs into a similar error message when attempting to connect to a Ubuntu VM running on VirtualBox, set a 2nd network adapter as "bridged" in network settings, and set up port forwarding on "NAT" to 22.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top