Scp command not working: connection closed by remote host (Mac OS X)

I am working on a remote server via the Mac terminal since I upgraded to OSX 10.10 from 10.5. I started getting this message every time I try to execute scp

from the server to my computer:

ssh_exchange_identification: Connection closed by remote host
lost connection

      

If I do scp

backward (copy from mac to server) it works fine and it works great if I do it by forming another mac.

If I do verobse scp

it gives me this:

Executing: program /usr/bin/ssh host xx.xx.xx.x, user User, command scp -v -t /Users/User
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to xx.xx.xx.x [xx.xx.xx.x] port 22.
debug1: Connection established.
debug1: identity file /home/user/.ssh/identity type -1
debug1: identity file /home/user/.ssh/identity-cert type -1
debug1: identity file /home/user/.ssh/id_rsa type -1
debug1: identity file /home/user/.ssh/id_rsa-cert type -1
debug1: identity file /home/user/.ssh/id_dsa type -1
debug1: identity file /home/user/.ssh/id_dsa-cert type -1
debug1: identity file /home/user/.ssh/id_ecdsa type -1
debug1: identity file /home/user/.ssh/id_ecdsa-cert type -1
ssh_exchange_identification: Connection closed by remote host
lost connection

      

I tried searching in various host, config, ssh files, but I couldn't solve much.

+3


source to share


6 answers


I had the same SCP issues from my personal Mac to the Mac desktop we use as a local server. Running it 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 to root (I'm not sure why that wasn't there yet, but I remember that upgrading from Mavericks to Yosemite gave me a couple of headaches regarding permissions):



cd /var
sudo chown root empty

      

Hope this helps.

+3


source


I have this problem too.

I tried "sudo sshd -t" but no problem.

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

Finally, I found out that I am using the '~' path in the command, here it is:



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

I changed it to the following:

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

      

And now it works. Hope this helps.

+2


source


Check target user .bashrc

or equivalent file. ~/.bashrc

used for non-interactive logins. If there is echo

or a command that outputs anything, it will violate the SCP protocol.

+1


source


'sudo sshd -t' clearly shows which config line is invalid. Got an SCP issue after commenting out this config line. Thanks a lot for the answers.

+1


source


System Preferences pane → Applet Sharing → select the Remote Login checkbox. This will allow the use of SSH and, in turn, SCP.

0


source


The user on the server and on your desktop must create keys locally before using ssh (or scp). You can create a strong key (RSA algorithm and length 4096) with this command:

ssh-keygen -t rsa -b 4096 -C "username"

      

If you already have the key on your server, check the permission on ~ / .ssh dir

As mentioned here , the owner of the .ssh file and the file in that directory must be your user. Permission for .ssh dir must be 700 (drwx ------) , private key files 600 (-rw ------) and public key must be 644 (-rw-r - r -) . You can check this with:

ls -alh

      

If it is not, you can change this:

   chown -R username ~/.ssh
   chmod 700 ~/.ssh
   chmod 600 ~/.ssh/id_*
   chmod 644 ~/.ssh/*.pub

      

-1


source







All Articles