您的位置:首页 > 其它

ssh: connect to host localhost port 22: Connection refused

2016-03-23 22:37 1221 查看
注:我遇到的问题比较复杂,所以最后没有解决,但前面几步应该可以解决你的问题。

记一次入坑之旅

drguo@drguo3:~/.ssh$ ssh localhost
ssh: connect to host localhost port 22: Connection refused
drguo@ubuntu:~$ sudo apt-get install openssh-server
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
有一些软件包无法被安装。如果您用的是 unstable 发行版,这也许是
因为系统无法达到您要求的状态造成的。该版本中可能会有一些您需要的软件
包尚未被创建或是它们已被从新到(Incoming)目录移出。
下列信息可能会对解决问题有所帮助:

下列软件包有未满足的依赖关系:
openssh-server : 依赖: openssh-client (= 1:5.9p1-5ubuntu1.8)
推荐: ssh-import-id 但无法安装它
E: 无法修正错误,因为您要求某些软件包保持现状,就是它们破坏了软件包间的依赖关系。


先是搜到这个:/article/7046071.html

来安装openssh-server,如果顺利的话会安装成功,如果遇到

这是因为,openssh-server是依赖于openssh-clien的,那ubuntu不是自带了openssh-client吗?原由是自带的openssh-clien与所要安装的openssh-server所依赖的版本不同,这里所依赖的版本是

所以要安装对应版本的openssh-clien,来覆盖掉ubuntu自带的

$ sudo apt-get install openssh-client=1:6.6p1-2ubuntu1
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
建议安装的软件包:
libpam-ssh keychain monkeysphere
下列软件包将被【降级】:
openssh-client
。。。。。。。。。。。。


感觉找到救星了,终于把openssh-server下下来了。然而还是!!!

drguo@drguo3:~/.ssh$ ssh localhost
ssh: connect to host localhost port 22: Connection refused
又搜到这个:http://asyty.iteye.com/blog/1440141

drguo@drguo3:~/.ssh$ ps -e | grep ssh
drguo@drguo3:~/.ssh$ /etc/init.d/ssh -start
* Usage: /etc/init.d/ssh {start|stop|reload|force-reload|restart|try-restart|status}
drguo@drguo3:~/.ssh$ /etc/init.d/ssh start
[....] Starting ssh (via systemctl): ssh.serviceJob for ssh.service failed because the control process exited with error code. See "systemctl status ssh.service" and "journalctl -xe" for details.
<pre name="code" class="plain">failed!



大哥它咋不按你说的来呢,并没有提示SSH不存在!!!而是failed!

drguo@drguo3:~/.ssh$ /etc/init.d/ssh status
● ssh.service - LSB: OpenBSD Secure Shell server
Loaded: loaded (/etc/init.d/ssh)
Active: failed (Result: exit-code) since 三 2016-03-23 22:47:34 CST; 6min ago
Docs: man:systemd-sysv-generator(8)
Process: 2568 ExecStart=/etc/init.d/ssh start (code=exited, status=1/FAILURE)

3月 23 22:47:34 drguo3 ssh[2568]: Rather than invoking init scripts throu...8)
3月 23 22:47:34 drguo3 ssh[2568]: utility, e.g. service ssh start
3月 23 22:47:34 drguo3 ssh[2568]: initctl: 无法连接到 Upstart: Failed to …连接
3月 23 22:47:34 drguo3 ssh[2568]: Since the script you are attempting to ...an
3月 23 22:47:34 drguo3 ssh[2568]: Upstart job, you may also use the start...sh
3月 23 22:47:34 drguo3 ssh[2568]: start: 无法连接到 Upstart: Failed to co…连接
3月 23 22:47:34 drguo3 systemd[1]: ssh.service: Control process exited, c...=1
3月 23 22:47:34 drguo3 systemd[1]: Failed to start LSB: OpenBSD Secure Sh...r.
3月 23 22:47:34 drguo3 systemd[1]: ssh.service: Unit entered failed state.
3月 23 22:47:34 drguo3 systemd[1]: ssh.service: Failed with result 'exit-...'.
Hint: Some lines were ellipsized, use -l to show in full.
怎么这么多问题啊!!!

我突然想到ssh-agent sshd都没有,是不是防火墙的问题

又搜到了这篇:http://www.idcbest.com/help/html/meirijiaodian/338.html

LInux原始的防火墙工具iptables由于过于繁琐,所以ubuntu系统默认提供了一个基于iptable之上的防火墙工具ufw。而UFW支持图形界面操作,只需在命令行运行ufw命令即能看到一系列的操作。接下来,就由专业运营香港服务器美国服务器韩国服务器等国外服务器的天下数据为大家介绍ubuntu系统防火墙的开启、关闭等常规操作命令。

启用ufw

sudo ufw enable

sudo ufw default deny

运行以上两条命令后,开启了防火墙,并在系统启动时自动开启。关闭所有外部对本机的访问,但本机访问外部正常。

关闭ubuntu的防火墙 ufw
disable

开启和禁用

sudo ufw allow|deny [service]

打开或关闭某个端口,例如:

sudo ufw allow smtp 允许所有的外部IP访问本机的25/tcp (smtp)端口

sudo ufw allow 22/tcp 允许所有的外部IP访问本机的22/tcp (ssh)端口

sudo ufw allow 53 允许外部访问53端口(tcp/udp)

sudo ufw allow from 192.168.1.100 允许此IP访问所有的本机端口

sudo ufw allow proto udp 192.168.0.1 port 53 to 192.168.0.2 port 53

sudo ufw deny smtp 禁止外部访问smtp服务

sudo ufw delete allow smtp 删除上面建立的某条规则

查看防火墙状态

sudo ufw status

允许某特定 IP

sudo ufw allow from xxx.xxx.xx.xxx

删除 smtp 端口的许可

sudo ufw delete allow smtp

立马试了一下

drguo@drguo1:~/.ssh$ sudo ufw status
[sudo] password for drguo:
状态:不活动
drguo@drguo1:~/.ssh$ ssh drguo1
ssh: connect to host drguo1 port 22: Connection refused
drguo@drguo1:~/.ssh$ ssh localhost
ssh: connect to host localhost port 22: Connection refused
drguo@drguo1:~/.ssh$ sudo ufw allow 22/tcp
跳过添加已经存在的规则
跳过添加已经存在的规则 (v6)
并没有问题!!!

drguo@drguo1:~/.ssh$ journalctl -xe
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --
-- Unit UNIT has finished shutting down.
3月 24 00:39:57 drguo1 systemd[1031]: Stopped target Basic System.
-- Subject: Unit UNIT has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --
-- Unit UNIT has finished shutting down.
3月 24 00:39:57 drguo1 systemd[1031]: Stopped target Paths.
-- Subject: Unit UNIT has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --
-- Unit UNIT has finished shutting down.
3月 24 00:39:57 drguo1 systemd[1031]: Stopped target Timers.
-- Subject: Unit UNIT has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --
-- Unit UNIT has finished shutting down.
3月 24 00:39:57 drguo1 systemd[1031]: Stopped target Sockets.
-- Subject: Unit UNIT has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --
-- Unit UNIT has finished shutting down.
3月 24 00:39:57 drguo1 systemd[1031]: Received SIGRTMIN+24 from PID 1794 (kill)
3月 24 00:39:57 drguo1 systemd[1]: Stopped User Manager for UID 119.
-- Subject: Unit user@119.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --
-- Unit user@119.service has finished shutting down.
3月 24 00:39:57 drguo1 systemd[1]: Removed slice user-119.slice.
-- Subject: Unit user-119.slice has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --
-- Unit user-119.slice has finished shutting down.
3月 24 00:40:38 drguo1 systemd-timesyncd[434]: Timed out waiting for reply from
3月 24 00:40:48 drguo1 systemd-timesyncd[434]: Timed out waiting for reply from
3月 24 00:42:02 drguo1 sudo[1831]:    drguo : TTY=pts/1 ; PWD=/home/drguo/.ssh
3月 24 00:42:02 drguo1 sudo[1831]: pam_unix(sudo:session): session opened for u
3月 24 00:42:02 drguo1 kernel: ip_tables: (C) 2000-2006 Netfilter Core Team
3月 24 00:42:03 drguo1 sudo[1831]: pam_unix(sudo:session): session closed for u
3月 24 00:42:30 drguo1 sudo[1843]:    drguo : TTY=pts/1 ; PWD=/home/drguo/.ssh
3月 24 00:42:30 drguo1 sudo[1843]: pam_unix(sudo:session): session opened for u
3月 24 00:42:31 drguo1 kernel: nf_conntrack version 0.5.0 (16384 buckets, 65536
3月 24 00:42:31 drguo1 kernel: ip6_tables: (C) 2000-2006 Netfilter Core Team
3月 24 00:42:31 drguo1 sudo[1843]: pam_unix(sudo:session): session closed for u
3月 24 00:42:44 drguo1 polkitd(authority=local)[758]: Registered Authentication
3月 24 00:42:44 drguo1 gnome-session[1404]: Gtk-Message: GtkDialog mapped witho
3月 24 00:42:48 drguo1 polkitd(authority=local)[758]: Operator of unix-session:
3月 24 00:42:48 drguo1 systemd[1]: Starting LSB: OpenBSD Secure Shell server...
-- Subject: Unit ssh.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --
-- Unit ssh.service has begun starting up.
3月 24 00:42:48 drguo1 ssh[1907]: Rather than invoking init scripts through /et
3月 24 00:42:48 drguo1 ssh[1907]: utility, e.g. service ssh start
3月 24 00:42:48 drguo1 ssh[1907]: initctl: 无法连接到 Upstart: Failed to connec
3月 24 00:42:48 drguo1 ssh[1907]: Since the script you are attempting to invoke
3月 24 00:42:48 drguo1 ssh[1907]: Upstart job, you may also use the start(8) ut
3月 24 00:42:48 drguo1 ssh[1907]: start: 无法连接到 Upstart: Failed to connect
3月 24 00:42:48 drguo1 systemd[1]: ssh.service: Control process exited, code=ex
3月 24 00:42:48 drguo1 systemd[1]: Failed to start LSB: OpenBSD Secure Shell se
-- Subject: Unit ssh.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel --
-- Unit ssh.service has failed.
哪位大神帮我搞一下吧,我已经崩溃了!!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: