SSH connection to localhost ssh_exchange_identification: Connection closed by remote host

localhostmacsshssh-keys

Setting up SSH access on local machine for a project.

When I ssh -v localhost my connection gets refused. With the following stack-trace.

OpenSSH_5.2p1, OpenSSL 0.9.8l 5 Nov 2009
debug1: Reading configuration data /Users/Kyle.Welsby/.ssh/config
debug1: Applying options for localhost
debug1: Applying options for *
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to localhost [::1] port 22.
debug1: Connection established.
debug1: identity file /Users/Kyle.Welsby/.ssh/identity type -1
debug1: identity file /Users/Kyle.Welsby/.ssh/id_rsa type 1
debug1: identity file /Users/Kyle.Welsby/.ssh/id_dsa type -1
ssh_exchange_identification: Connection closed by remote host

My ssh configuration is the standard Mac OS X setup. With the following alterations.

# /etc/sshd_config
PermitUserEnvironment yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

# ~/.ssh/config
Host localhost
User Kyle.Welsby

Best Answer

The issue happened to be PermitUserEnvironment yes I commented this out and all worked fine-ish.