ssh connection refused

本文解决了一个常见的SSH连接问题,即连接到本地主机时出现“Connection refused”的错误。通过检查SSH服务状态及端口监听情况,最终成功启动了SSH服务并实现了正常连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ssh: connect to host localhost port 22: Connection refused

问题

在使用ssh连接时出现:

$ ssh localhost
ssh: connect to host localhost port 22: Connection refused

分析

SSH是否开启,端口是否监听

检查端口是否监听
$ ss -tnlp
State     Recv-Q      Send-Q            Local Address:Port             Peer Address:Port

从命令结果可以看到,SSH的监听端口(22)并没有

检查sshd.service服务是否开启
$ systemctl status sshd.service
● sshd.service - OpenSSH Daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

sshd.service没有没有激活

原因

ssh服务没有启动,端口未处于监听状态

解决
$ systemctl start sshd.service
$ systemctl status sshd.service
● sshd.service - OpenSSH Daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2018-04-22 23:51:43 CST; 6s ago
 Main PID: 9429 (sshd)
    Tasks: 1 (limit: 4915)
   Memory: 1.7M
   CGroup: /system.slice/sshd.service
           └─9429 /usr/bin/sshd -D

4月 22 23:51:43 xiaoliu-manjaro systemd[1]: Started OpenSSH Daemon.
4月 22 23:51:43 xiaoliu-manjaro sshd[9429]: Server listening on 0.0.0.0 port 22.
4月 22 23:51:43 xiaoliu-manjaro sshd[9429]: Server listening on :: port 22.
$ ss -tmlp
State      Recv-Q      Send-Q            Local Address:Port            Peer Address:Port                                                                                                    
LISTEN     0           128                     0.0.0.0:ssh                  0.0.0.0:*         
     skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0,d0)                                              
LISTEN     0           128                        [::]:ssh                     [::]:*         
     skmem:(r0,rb87380,t0,tb16384,f0,w0,o0,bl0,d0)
$ ssh localhost
Last login: Sun Apr 22 17:22:36 2018 from ::1

附录

命令

  • ss -tnlp
  • systemctl status sshd.service
  • systemctl start sshd.service
  • ssh localhost

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值