sudo apt-get install -y openssh-server安装一下软件,我这里已经安装好了,所以没有安装过程了。

firewall-cmd --zone=public --remove-port=22/tcp --permanent想要打开22端口,发现报错如下:
Could not find command-not-found database. Run 'sudo apt update' to populate it.
firewall-cmd: command not found

iptables -A INPUT -p tcp --dport 22 -j DROP打开22端口。

ip addr可以看一下ip,我的这里的ip是192.168.0.109。

使用putty连接发现还是报错Network error: Connection time out。

systemctl status ssh发现状态是inactive (dead)。

systemctl start ssh打开ssh服务,然后再次使用systemctl status ssh发现状态是active (running),这就是开启了。

使用putty连接发现还是报错Network error: Connection time out。

ping 192.168.0.109有数据显示,说明网络是互通的。

lsof -i:22看一下22端口是否打开,要是有信息显示就是打开了。我这里就是打开了。

以前没有遇到过这种情况,网上去搜索一下情况,参考《Putty 远程 连接kali Linux拒绝访问 refused connection》。
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config把字符串#PermitRootLogin prohibit-password改成PermitRootLogin yes。

systemctl restart ssh重新启动ssh服务,然后再次使用systemctl status ssh发现状态是active (running)。

使用putty连接发现还是报错Network error: Connection time out。

上边iptables -A INPUT -p tcp --dport 22 -j DROP不是打开22端口,而是关闭。iptables -A INPUT -p tcp --dport 22 -j ACCEPT打开22端口,然后使用iptables -t filter -nvL看一下过滤情况。

发现第一条还是关闭22端口的情况,所以使用iptables -t filter -D INPUT 1把第一条过滤链给删除,iptables -t filter -nvL再看一下过滤链,发现没有22端口DROP的记录。

再次使用putty进行连接,填写完ip,之后右下角点击Open。

先输入用户名kail,之后再输入密码,注意密码不可见,只要密码正确就能正常登录。




















