unix scp命令不工作:连接被远程主机关闭(Mac OS X)[关闭]

y3bcpkx1  于 7个月前  发布在  Unix
关注(0)|答案(9)|浏览(146)

**已关闭。**此问题为not about programming or software development。目前不接受回答。

此问题似乎与a specific programming problem, a software algorithm, or software tools primarily used by programmers无关。如果您认为此问题与another Stack Exchange site的主题相关,可以发表评论,说明在何处可以回答此问题。
25天前关闭
Improve this question
我正在通过Mac终端在远程服务器上工作,因为我将其从10.5更新到OSX 10.10我开始收到此消息,每次我尝试从服务器scp到我的计算机:

ssh_exchange_identification: Connection closed by remote host
lost connection

字符串
如果我向后执行scp(从mac复制到服务器),它工作得很好,如果我从另一个mac复制,它工作得很好。
如果我做一个verobse scp,它会给我这个:

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


我试着在各种主机,配置,ssh文件中查找,但我没有解决太多问题。

krcsximq

krcsximq1#

我刚刚遇到了同样的问题,从我的个人Mac到我们用作本地服务器的Mac桌面的SCP。运行sudo sshd -t向我展示了以下提示:

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

字符串
我所做的就是把所有者改回root(我不知道为什么还没有,但我记得从Mavericks升级到约塞米蒂让我在权限方面头疼):

cd /var
sudo chown root empty


希望能帮上忙。

vqlkdk9b

vqlkdk9b2#

我也有这个问题。
我试过“sudo sshd -t”,但似乎没有问题。
然后我检查了我的“主机.允许”&“主机.拒绝”,没有问题乙醚。
最后我发现我使用了 *'~'**path int命令,如下:
第一个月
我把它改成了下面的一个:

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

字符串

现在可以用了希望能帮到你。

cetgtptt

cetgtptt3#

检查目标用户的.bashrc或等效文件。~/.bashrc用于非交互式登录。如果有echo或命令输出任何内容,则会破坏SCP协议。

lztngnrs

lztngnrs4#

'sudo sshd -t'清楚地显示了哪个配置行是无效的。在注解了那个配置行后,解决了SCP问题。非常感谢您的回答。

uplii1fm

uplii1fm5#

系统偏好设置面板→共享小程序→选中远程登录复选框。这将启用SSH,并依次启用SCP。

t98cgbkg

t98cgbkg6#

我在使用scp -P [wrong_custom_port] user@host:/source /destination时也遇到了同样的错误
在谷歌搜索了一段时间,没有找到任何直接的答案,我终于意识到,我使用不同的自定义端口号为我的ssh连接在远程主机上。
希望这对有类似问题的人有所帮助。

uz75evzq

uz75evzq7#

我会把我的帽子扔在戒指上。
我得到了这个问题有点困扰今天试图scp一个文件从一台电脑在我的局域网到我的macbook,并得到了可爱的消息,以STDOUT

scp: Connection closed

字符串
这并没有给给予我太多的工作空间,添加-VVVV也没有显示出任何明显的问题,尽管当这样的东西不起作用时使用-VVVV并不是我每天都会看到的(可能错过了一些东西)。
以上sudo sshd -t命令将nothing打印到STDOUT。
那么接下来该怎么办呢,幸运的是,我在过去经历过ssh的问题,和IMHO最简单的方法来获得一个关于为什么某个ssh相关任务的 sane 消息,即. scping 文件到某种ssh服务器是停止当前运行的服务器,并从前台进程的终端以调试模式启动它(如果ssh配置文件设置正确,可能会启动另一个ssh服务器以防止停止现有的服务器(我没有研究过)),但对于我的使用,停止现有的服务器并在debug中启动它的新示例🧙‍会产生很好的效果️,所以运行

sshd -d


然后尝试向服务器发送文件,我在STDOUT中看到以下行

debug1: server_input_channel_req: channel 0 request subsystem reply 1
debug1: session_by_channel: session 0 channel 0
debug1: session_input_channel_req: session 0 req subsystem
debug1: subsystem: cannot stat /usr/local/Cellar/openssh/8.8p1/libexec/sftp-server: No such file or directory
debug1: subsystem: exec() /usr/local/Cellar/openssh/8.8p1/libexec/sftp-server
Starting session: subsystem 'sftp' for capin from 10.0.1.42 port 63866 id 0
debug1: Received SIGCHLD.
debug1: session_by_pid: pid 2107
debug1: session_exit_message: session 0 channel 0 pid 2107
debug1: session_exit_message: release channel 0
Received disconnect from 10.0.1.42 port 63866:11: disconnected by user
Disconnected from user capin 10.0.1.42 port 63866
debug1: do_cleanup
debug1: do_cleanup
debug1: PAM: cleanup
debug1: PAM: closing session
debug1: PAM: deleting credentials


这让我认为那些错误/警告消息是我的问题,并从那里继续故障排除。

4dc9hkyq

4dc9hkyq8#

Add -O(字母)
scp -O { filename } {user}@{ip}:{path}
示例:scp -O filename.txt email protected(https://stackoverflow.com/cdn-cgi/l/email-protection):/usr/home

eoigrqb6

eoigrqb69#

在使用ssh(或scp)之前,服务器和桌面上的用户必须在本地创建密钥。您可以使用以下命令创建强密钥(算法RSA和长度4096):

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

字符串
如果你已经在你的服务器上有密钥,检查**~/.ssh目录的权限
here所述,.ssh目录和该目录中的文件的所有者必须是您的用户。
.ssh目录的权限必须为700(drwx-),私钥文件必须为600(-rw-),公钥必须为644(-rw-r--r--)**。您可以通过以下方式检查:

ls -alh


如果不是这样,你可以改变它:

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

相关问题