Not working scp command: Connection closed by remote host (Mac OS X) Not working scp command: Connection closed by remote host (Mac OS X) unix unix

Not working scp command: Connection closed by remote host (Mac OS X)


I just had the same issues with an SCP from my personal Mac to a Mac desktop we use as a local server. Running sudo sshd -t showed me the following hint:

/var/empty must be owned by root and not group or world-writable

All I did was change the owner back to root (I'm not sure why it wasn't already, but I remember upgrading from Mavericks to Yosemite gave me a couple headaches regarding permissions):

cd /varsudo chown root empty

I hope it helps.


I got this problem too.

I tried "sudo sshd -t" , but there seemed no problem.

Then I checked my "hosts.allow" & "hosts.deny", no problem ether.

Finally I found out that I use the '~' path int the command, here's it:

scp ~/Downloads/afile root@host2:~/Downloads

I changed it to the following one:

scp /home/Downloads/afile root@host2:/home/Downloads

And it works now. Hope this can help.


Check the target user's .bashrc or equivalent file. ~/.bashrc is sourced for non-interactive logins. If there's an echo or command that outputs anything, it will break the SCP protocol.