ssh: connect to host localhost port 22: Connection refused(ubuntu14.04_LTS)

来源:互联网 发布:如何查看淘宝店铺粉丝 编辑:程序博客网 时间:2024/06/03 13:01

安装hadoop时需要先安装无密钥ssh登陆。到ssh localhost这一步时却报出如下的错误:

ssh: connect to host localhost port 22: Connection refused

在网上多翻搜索,总结原因大概3个如下
1、ssh-server未安装或者未启动
这个问题可用2条语句一次性解决。

sudo apt-get remove openssh-server openssh-clientsudo apt-get install openssh-server openssh-client 

把client和server卸载重新安装。网上还有的说client与server之间还有什么依赖关系之类,个人觉得应该是相互独立的。重新安装那这方面的问题也就一次解决了。
2、防火墙未关闭

sudo ufw disable   

3、端口被占用

lsof -i:22

如果有进程占用端口,kill pid即可。或者将端口号更改。
无奈的是本人前述方法都试过了,但还是报错。那就说明不是这些问题了。
后来google了下。提到/etc/ssh/ssh_config文件配置需要更改下。
我将配置文件中端口号与协议两条语句放开就解决了这个问题。

# This is the ssh client system-wide configuration file.  See# ssh_config(5) for more information.  This file provides defaults for# users, and the values can be changed in per-user configuration files# or on the command line.# Configuration data is parsed as follows:#  1. command line options#  2. user-specific file#  3. system-wide file# Any configuration value is only changed the first time it is set.# Thus, host-specific definitions should be at the beginning of the# configuration file, and defaults at the end.# Site-wide defaults for some commonly used options.  For a comprehensive# list of available options, their meanings and defaults, please see the# ssh_config(5) man page.Host *#   ForwardAgent no#   ForwardX11 no#   ForwardX11Trusted yes#   RhostsRSAAuthentication no#   RSAAuthentication yes#   PasswordAuthentication yes#   HostbasedAuthentication no#   GSSAPIAuthentication no#   GSSAPIDelegateCredentials no#   GSSAPIKeyExchange no#   GSSAPITrustDNS no#   BatchMode no#   CheckHostIP yes#   AddressFamily any#   ConnectTimeout 0#   StrictHostKeyChecking ask#   IdentityFile ~/.ssh/identity#   IdentityFile ~/.ssh/id_rsa#   IdentityFile ~/.ssh/id_dsaPort 22Protocol 2#   Protocol 2,1#   Cipher 3des#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160#   EscapeChar ~#   Tunnel no#   TunnelDevice any:any#   PermitLocalCommand no#   VisualHostKey no#   ProxyCommand ssh -q -W %h:%p gateway.example.com#   RekeyLimit 1G 1h    SendEnv LANG LC_*    HashKnownHosts yes    GSSAPIAuthentication yes    GSSAPIDelegateCredentials no

登陆效果如图

每天进步一点点。
:)

0 0
原创粉丝点击