ssh connection refused 問題


以下內容引用自:ephererid的文章

https://segmentfault.com/a/1190000014532520

問題

在使用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

注意:

使用 ss -tnlp 時可能 ssh 的默認端口號不是 22,如果不想修改默認端口號,則可以直接使用其正在運行的可用端口。

參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM