在ubuntu中配置SSH(解决connect to host localhost port 22: Connection refused问题)

亲测有效

命令:ssh localhost
错误信息:ssh: connect to host localhost port 22: Connection refused

错误原因:
1.sshd 未安装
2.sshd 未启动

3.防火墙

4需重新启动ssh 服务

解决方法:
1.确定安装sshd:

$ sudo apt-get install openssh-server   

2.启动sshd:

$ sudo net start sshd    

3.检查防火墙设置,关闭防火墙:

$ sudo ufw disable    

检验方法:
输入命令:

$ ssh localhost    

若成功,则表示安装成功,且连接通过;

但是有的时候虽然成功了但是还是会出现Connection refused 问题。

运行 ps -e | grep ssh,查看是否有sshd进程

有时候虽然可以看到sshd 但是还是不能连接成功

这时候就要想到重新启动一下:sudo service ssh restart

然后在连接

你可能感兴趣的:(在ubuntu中配置SSH(解决connect to host localhost port 22: Connection refused问题))