【问题标题】:SSh: Connection refused to localhostSSh:拒绝连接到本地主机
【发布时间】:2016-09-26 01:08:58
【问题描述】:

我想将 hadoop 安装到 ubuntu。

我正在关注本教程:Running Hadoop on Ubuntu Linux

但是我在步骤ssh localhost遇到了一个问题

hduser@r:~$ ssh -vvv localhost -p 8047
OpenSSH_6.2p2 Ubuntu-6ubuntu0.1, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to localhost [127.0.0.1] port 8047.
debug1: connect to address 127.0.0.1 port 8047: Connection refused
ssh: connect to host localhost port 8047: Connection refused

hduser@r:~$ which ssh
/usr/bin/ssh
hduser@r:~$ which sshd
hduser@r:~$ 

这是我的 /etc/ssh/sshd_config:

仅添加最后 5 行!

# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

AllowGroups hduser


# disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

在此先感谢(也感谢您不投票:D))

编辑:

hduser@r:~$ r@r:~$ netstat -tulpn

tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.1.1:53            0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:17500           0.0.0.0:*               LISTEN      -               
udp        0      0 127.0.1.1:53            0.0.0.0:*                           -               
udp        0      0 0.0.0.0:68              0.0.0.0:*                           -               
udp        0      0 0.0.0.0:631             0.0.0.0:*                           -               
udp        0      0 0.0.0.0:17500           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -               
udp        0      0 0.0.0.0:26575           0.0.0.0:*                           -               
udp        0      0 0.0.0.0:47235           0.0.0.0:*                           -               
-         

【问题讨论】:

  • mbratch 说了什么!如果不是,则运行sudo service sshd start
  • 出现错误,sshd:来自sudo service sshd start的服务无法识别
  • 你有什么理由相信 anything 会监听 8047 端口?特别是如果你没有这样配置?
  • 您链接到的教程没有 SSH 命令行的 -p 8047 参数。那是从哪里来的呢?
  • 您的sshd_config 清楚地表明Port 22,因此尝试在端口8047 上联系它毫无意义...此外,您禁用IPv6 的尝试看起来更像sysctl 行,并且不属于sshd_config...

标签: linux ubuntu hadoop ssh


【解决方案1】:

你需要安装openssh服务器

sudo apt-get install openssh-server

【讨论】:

    【解决方案2】:

    不要惊慌!你的命令不正确。

    ssh -vvv localhost -p 8047
    

    参数-p 8047表示访问端口8047,但是SSH守护进程运行在端口22。您粘贴的sshd配置已经证明了我的假设。

    您可以尝试使用 SSH 访问本地主机

    ssh hduser@localhost
    

    【讨论】:

    • 我知道-p 8047 是错误的。但是ssh hduser@localhost 帮助我找到了问题。它给了Offending ECDSA key in /home/hduser/.ssh/known_hosts:1 remove with: ssh-keygen -f "/home/hduser/.ssh/known_hosts" -R localhost。然后它在ssh-keygen -f "/home/hduser/.ssh/known_hosts" -R localhost 命令之后工作。
    【解决方案3】:

    运行netstat -tulpn 以查看哪些服务正在运行以及在哪些端口上运行。请注意,您可能需要更改选项,但 Ubuntu 和 Fedora 使用“-tulpn”选项可以正常工作。

    【讨论】:

    • 我更新了我的问题并添加了 netstat -tulpn 的结果
    • netstat 的输出显示了哪些服务正在监听哪些端口。您发布的输出显示端口 8047 上没有任何监听,因此您收到连接被拒绝错误是有道理的。如果你真的想通过那个端口连接,你需要让你的 sshd 监听它。
    【解决方案4】:

    您可以在 ubuntu 中使用 PuTTY SSH Client 工具,如下例所示:

    1 - 将您的 IPPort numberConnection type 设置为 SSH

    2 - 输入您的 usernamepassword

    3 - 现在您以Logined 进入路由器配置,状态为Secure Shell。 这个解决方案非常安全,任何人都不能sniffauthentication

    【讨论】:

      【解决方案5】:

      其实我解决了这个问题,我只是安装了 shh 守护进程。

      在终端:

      sudo apt-get install openssh-server
      

      【讨论】:

        猜你喜欢
        • 2019-10-29
        • 1970-01-01
        • 2016-08-25
        • 1970-01-01
        • 1970-01-01
        • 2015-07-30
        • 2011-11-05
        • 1970-01-01
        • 2023-01-19
        相关资源
        最近更新 更多