Ubuntu 22.04服务器SSH可正常连接但SCP传输被拒绝的问题求助
Ubuntu 22.04服务器SSH可正常连接但SCP传输被拒绝的问题求助
各位好,我现在用Ubuntu 22.04搭了个服务器,SSH连接完全没问题,但从同局域网的Windows 10机器上用SCP传文件时,一直弹出“Connection refused”错误,实在摸不着头脑,想问问大家有没有遇到过类似情况?
我执行的SCP命令是:
scp -vvvv -P 22 "Pokémon Diamond & Pearl Sinnoh Map.jpg" ubuntu@192.168.0.110:./
下面是详细的报错输出:
Executing: program ssh.exe host 192.168.0.110, user ubuntu, command scp -v -t ./ OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2 debug3: Failed to open file:C:/Users/Dark/.ssh/config error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2 debug2: resolve_canonicalize: hostname 192.168.0.110 is address debug2: ssh_connect_direct debug1: Connecting to 192.168.0.110 [192.168.0.110] port 22. debug3: finish_connect - ERROR: async io completed with error: 10061, io:0000020BB6497460 debug1: connect to address 192.168.0.110 port 22: Connection refused ssh: connect to host 192.168.0.110 port 22: Connection refused lost connection
我已经尝试过这些排查步骤:
- 开放22端口:执行了
sudo ufw allow 22,但查ufw状态显示是inactive的 - 重置了.bashrc:
cp /etc/skel/.bashrc ~/ - 检查SSH守护进程状态,显示服务已经正常启动并监听22端口:
$ systemctl status ssh ● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2024-01-27 21:36:24 JST; 3s ago Docs: man:sshd(8) man:sshd_config(5) Process: 28095 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS) Main PID: 28096 (sshd) Tasks: 1 (limit: 1660) Memory: 1.6M CPU: 65ms CGroup: /system.slice/ssh.service └─28096 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups" Jan 27 21:36:24 ubuntu systemd[1]: Starting OpenBSD Secure Shell server... Jan 27 21:36:24 ubuntu sshd[28096]: Server listening on 0.0.0.0 port 22. Jan 27 21:36:24 ubuntu sshd[28096]: Server listening on :: port 22. Jan 27 21:36:24 ubuntu systemd[1]: Started OpenBSD Secure Shell server.
我一直理解SCP是基于SSH协议的,既然SSH能正常连接,为什么SCP会被拒绝呢?是不是有什么我忽略的细节?
编辑补充:我后来还试了22端口和网上看到的8022端口,结果都不行,8022对应的命令是:
scp -vvvv -P 8022 "Pokémon Diamond & Pearl Sinnoh Map.jpg" ubuntu@192.168.0.110:./
更新(应@user68186要求补充):我是在Windows Terminal的cmd环境下运行SSH和SCP命令的,SSH连接完全正常,下面是成功登录的输出:
ssh ubuntu@192.168.0.110 ubuntu@192.168.0.110's password: Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-1037-raspi aarch64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Sat Jan 27 22:58:44 JST 2024 System load: 0.0068359375 Temperature: 48.7 C Usage of /: 58.7% of 28.94GB Processes: 280 Memory usage: 47% Users logged in: 2 Swap usage: 11% IPv4 address for wlan0: 192.168.0.110 * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s just raised the bar for easy, resilient and secure K8s cluster deployment. Expanded Security Maintenance for Applications is not enabled. 254 updates can be applied immediately. 175 of these updates are standard security updates. To see these additional updates run: apt list --upgradable 30 additional security updates can be applied with ESM Apps. Learn more about enabling ESM Apps service at https://ubuntu.com/esm Last login: Sat Jan 27 19:29:14 2024 from 192.168.0.102
最终更新:折腾了好长时间排查这个SCP的问题,现在发现SFTP和Samba都能正常使用,我打算先改用这两个工具,把时间放到别的事情上。非常感谢大家的建议和帮助,如果有人还想继续深挖这个问题也完全没问题,祝大家顺利!
备注:内容来源于stack exchange,提问作者N00B_141
相关产品推荐
相关产品推荐

