ssh connection refused

ssh: connect to host localhost port 22: Connection refused

question

When connecting using ssh it appears:

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

analyze

Whether SSH is enabled and whether the port is listening

Check if port is listening

$ ss -tnlp
State     Recv-Q      Send-Q            Local Address:Port             Peer Address:Port

As you can see from the command results, the SSH listening port (22) does not

Check whether the sshd.service service is enabled

$ 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 is not activated

reason

The ssh service is not started and the port is not in the listening state

solve

$ 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

appendix

Order

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

refer to

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324695069&siteId=291194637