当前位置:   article > 正文

Ubuntu SSH - ssh: connect to host ****** port 22: Connection refused_ubuntu20.04.4 (port 22): connection failed.

ubuntu20.04.4 (port 22): connection failed.

OpenSSH is the premier connectivity tool for remote login with the SSH protocol. It encrypts all traffic to eliminate eavesdropping, connection hijacking, and other attacks. In addition, OpenSSH provides a large suite of secure tunneling capabilities, several authentication methods, and sophisticated configuration options.

eavesdrop ['iːvzdrɒp]:n. 屋檐上流下来的水 vi. 偷听,窃听
hijack ['haɪdʒæk]:vt. 抢劫,揩油 vi. 拦路抢劫 n. 劫持,威逼,敲诈
premier [ˈpremiə(r)]:n. 总理,地区总理 adj. 首要的,最著名的,最成功的,第一的
tunnel ['tʌn(ə)l]:n. 隧道,地道,地下通道,(动物的) 洞穴通道,隧道,地道,坑道,风洞,隧道,地道,坑道,烟道 v. 在 ... 凿隧道,凿隧道通过,运过坑道 进隧道,在 ... 凿隧道,凿隧道通过,运过坑道进隧道,开凿隧道,挖地道
sophisticate [səˈfɪstɪkeɪt]:v. 用诡辩欺骗,使迷惑,窜改,掺坏 n. 老于世故的人,见多识广的人
  • 1
  • 2
  • 3
  • 4
  • 5

1. ssh: connect to host ****** port 22: Connection refused

strong@foreverstrong 通过 SSH 连接 IBM@IBM-computer 失败,ssh: connect to host 192.168.2.56 port 22: Connection refused

strong@foreverstrong:~$ ssh IBM@192.168.2.56
ssh: connect to host 192.168.2.56 port 22: Connection refused
strong@foreverstrong:~$
  • 1
  • 2
  • 3

IBM@IBM-computer 通过 ssh localhost 连接本机失败,ssh: connect to host localhost port 22: Connection refused

IBM@IBM-computer:~$ ssh localhost
ssh: connect to host localhost port 22: Connection refused
IBM@IBM-computer:~$
  • 1
  • 2
  • 3

2. 检查 ssh 服务状态

使用 ps -e | grep ssh 命令检查 openssh-server 服务是否在线。

IBM@IBM-computer:~$ ssh localhost
ssh: connect to host localhost port 22: Connection refused
IBM@IBM-computer:~$ 
IBM@IBM-computer:~$ ps -e | grep ssh
IBM@IBM-computer:~$
  • 1
  • 2
  • 3
  • 4
  • 5

3. 安装 openssh-server

Ubuntu 默认没有安装 ssh 服务,需要手动安装 openssh-server。

IBM@IBM-computer:~$ sudo apt-get install openssh-server
[sudo] password for IBM: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ncurses-term openssh-sftp-server ssh-import-id
Suggested packages:
  ssh-askpass rssh molly-guard monkeysphere
The following NEW packages will be installed:
  ncurses-term openssh-server openssh-sftp-server ssh-import-id
0 upgraded, 4 newly installed, 0 to remove and 322 not upgraded.
Need to get 633 kB of archives.
After this operation, 5,136 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 ncurses-term all 6.0+20160213-1ubuntu1 [249 kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-sftp-server amd64 1:7.2p2-4ubuntu2.4 [38.7 kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu xenial-updates/main amd64 openssh-server amd64 1:7.2p2-4ubuntu2.4 [335 kB]
Get:4 http://cn.archive.ubuntu.com/ubuntu xenial/main amd64 ssh-import-id all 5.5-0ubuntu1 [10.2 kB]
Fetched 633 kB in 7s (83.9 kB/s)                                               
Preconfiguring packages ...
Selecting previously unselected package ncurses-term.
(Reading database ... 184475 files and directories currently installed.)
Preparing to unpack .../ncurses-term_6.0+20160213-1ubuntu1_all.deb ...
Unpacking ncurses-term (6.0+20160213-1ubuntu1) ...
Selecting previously unselected package openssh-sftp-server.
Preparing to unpack .../openssh-sftp-server_1%3a7.2p2-4ubuntu2.4_amd64.deb ...
Unpacking openssh-sftp-server (1:7.2p2-4ubuntu2.4) ...
Selecting previously unselected package openssh-server.
Preparing to unpack .../openssh-server_1%3a7.2p2-4ubuntu2.4_amd64.deb ...
Unpacking openssh-server (1:7.2p2-4ubuntu2.4) ...
Selecting previously unselected package ssh-import-id.
Preparing to unpack .../ssh-import-id_5.5-0ubuntu1_all.deb ...
Unpacking ssh-import-id (5.5-0ubuntu1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for systemd (229-4ubuntu21.1) ...
Processing triggers for ureadahead (0.100.0-19) ...
ureadahead will be reprofiled on next reboot
Setting up ncurses-term (6.0+20160213-1ubuntu1) ...
Setting up openssh-sftp-server (1:7.2p2-4ubuntu2.4) ...
Setting up openssh-server (1:7.2p2-4ubuntu2.4) ...
Creating SSH2 RSA key; this may take some time ...
2048 SHA256:VKvdcDxChl0z+xJ84O/VDjQWhR0c7PJWAJ2C+kD0jyQ root@IBM-computer (RSA)
Creating SSH2 DSA key; this may take some time ...
1024 SHA256:bMHTBGJvRzmqWeA+kuHFGifIjWg2SDwjs+sVzBgq9Ig root@IBM-computer (DSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:EvlBk/pUm3nBLH5dOdVihIRVyXftkEVz3StM9rthX8M root@IBM-computer (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:EMZZCbuDWBMwN2uvFTjv1feMTJSm+41pQgndcLyfYsk root@IBM-computer (ED25519)
Setting up ssh-import-id (5.5-0ubuntu1) ...
Processing triggers for systemd (229-4ubuntu21.1) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
IBM@IBM-computer:~$ 
IBM@IBM-computer:~$ ps -e | grep ssh
 3059 ?        00:00:00 sshd
IBM@IBM-computer:~$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58

ssh 服务开启,启动 ssh 服务:

sudo service sshd start
sudo service sshd restart
  • 1
  • 2

ssh localhost 命令用来连接本机,ssh username@hostname(or IP)
由于默认关闭了 ssh 服务,连接无法建立,第一次连接需要手动输入 yes,才能建立连接。

IBM@IBM-computer:~$ ssh localhost
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:EvlBk/pUm3nBLH5dOdVihIRVyXftkEVz3StM9rthX8M.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
IBM@localhost's password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

316 packages can be updated.
107 updates are security updates.


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

IBM@IBM-computer:~$ 
IBM@IBM-computer:~$ exit
logout
Connection to localhost closed.
IBM@IBM-computer:~$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
strong@foreverstrong:~$ ssh IBM@192.168.2.56
The authenticity of host '192.168.2.56 (192.168.2.56)' can't be established.
ECDSA key fingerprint is SHA256:EvlBk/pUm3nBLH5dOdVihIRVyXftkEVz3StM9rthX8M.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.56' (ECDSA) to the list of known hosts.
IBM@192.168.2.56's password: 
Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.10.0-28-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

316 packages can be updated.
107 updates are security updates.

Last login: Tue Oct 16 17:12:43 2018 from 127.0.0.1
IBM@IBM-computer:~$ 
IBM@IBM-computer:~$ exit
logout
Connection to 192.168.2.56 closed.
strong@foreverstrong:~$
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

References

[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/668856
推荐阅读
相关标签
  

闽ICP备14008679号