我正在尝试解锁我正在进行某些测试的IP。我已经按照网上的教程进行了操作:
$ sudo /etc/init.d/denyhosts stop
$ sudo vim /etc/deny.hosts
[remove the last line where I can see my IP to clear]
$ cd /var/lib/denyhosts/
$ sudo vim *
[remove any occurences of my IP to clear]
$ sudo /etc/init.d/denyhosts start
此时我的IP出现在/etc/deny.hosts中。我也试过了:
$ cd /var/lib/denyhosts/
$ echo '123.456.789.122' >> /var/lib/denyhosts/allowed-hosts
我也尝试过:
$ echo 'my.ip.to.clear' >> /etc/hosts.allow
不幸的是,hosts.deny始终优先,拒绝ssh连接,从日志文件中可以看出:
2月10日10:06:24 ks123456 sshd [22875]:拒绝连接 123.456.789.122(123.456.789.122)
ref:debian / 6.0.4,denyhosts 2.6-10
答案 0 :(得分:33)
这对Centos有用。按照下面的8个步骤,你应该很高兴。
停止DenyHosts
# services denyhosts stop
从/etc/hosts.deny
修改/var/lib/denyhosts/hosts
并删除包含IP地址的行。保存文件。
修改/var/lib/denyhosts/hosts-restricted
并删除包含IP地址的行。保存文件。
修改/var/lib/denyhosts/hosts-root
并删除包含IP地址的行。保存文件。
修改/var/lib/denyhosts/hosts-valid
并删除包含IP地址的行。保存文件。
修改/var/lib/denyhosts/users-hosts
并删除包含IP地址的行。保存文件。
(可选)考虑将IP地址添加到/ var / lib / denyhosts / allowed-hosts
启动DenyHosts
# services denyhosts start
答案 1 :(得分:8)
可以在此处找到删除denyhosts条目的说明:http://www.cyberciti.biz/faq/linux-unix-delete-remove-ip-address-that-denyhosts-blocked/。在Ubuntu中,denyhosts数据文件位于/var/lib/denyhosts
。
/var/log/auth.log
它可以为您提供问题的线索。我自己遇到了问题,因为我使用sftp将KDE上的Dolphin保存到我的服务器上。 Dolphin使用您当前的用户名尝试登录,这会将我的IP添加到hosts.deny文件中。
答案 2 :(得分:7)
只需添加应始终有权访问该文件的IP:
/etc/hosts.allow
该条目可能如下:
ALL: 30.20.10.0/24
这样,即使它最终都在/etc/hosts.deny
,IP仍然可以访问。
介意 {<1}} 之前知识产权,我发现您忘记了ALL
声明。
参考文献:
答案 3 :(得分:7)
如果上述说明没有帮助,denyhosts可能会将IP添加到iptables防火墙。
iptables -L -n -v | grep xxx.xxx.xxx.xxx
如果你看到类似的东西:
0 0 DROP all -- * * xxx.xxx.xxx.xxx 0.0.0.0/0
从防火墙中删除所需的IP:
iptables -D INPUT -s xxx.xxx.xxx.xxx -j DROP
重新启动网络以应用更改:
/etc/init.d/networking restart
答案 4 :(得分:3)
您可以在4个命令中执行此操作。它使用python脚本自动化@Abdellatif的早期答案,因此在将这4行粘贴到命令提示符(用IP地址替换IP_ADDRESS)之前,您应该彻底浏览source:
sudo /etc/init.d/denyhosts stop
git clone https://github.com/rsprabery/unblock.git
sudo python unblock/unblock.py <IP_ADDRESS>
sudo /etc/init.d/denyhosts start
它应该适用于所有Ubuntu系统。而且速度很快。而且您不必编辑任何文件。但是,你正在运行别人的脚本作为sudo。
答案 5 :(得分:3)
这是在CentOS 6.7上对我有用的东西
./daemon-control stop
/etc/hosts.deny
/usr/share/denyhosts/data/hosts
/usr/share/denyhosts/data/hosts-restricted
/usr/share/denyhosts/data/hosts-root
/usr/share/denyhosts/data/hosts-valid
/usr/share/denyhosts/data/users-hosts
/usr/share/denyhosts/data/allowed-hosts
。该文件只需要每行一个IP。此文件中显示的任何IP地址都不会被阻止。./daemon-control start
答案 6 :(得分:2)
添加一个旧问题,但在Debian Wheezy上删除IP条目没有帮助:在运行的几秒钟内&#34; service denyhost start&#34; IP将重新添加到hosts.deny和/ var / lib / denyhosts /中的所有文件。事实证明,DenyHosts正在重新扫描/var/log/auth.log,其中包括失败的登录尝试。
从上面列出的文件中删除IP条目后,在重新启动denyhosts之前,通过运行(以root身份)强制存档auth.log:
logrotate -vf /etc/logrotate.d/rsyslog
仔细检查/var/log/auth.log是否为空,然后重新启动denyhosts。
答案 7 :(得分:1)
Ubuntu 18.04
IP_UNBLOCK='1.2.3.4'
systemctl stop denyhosts
sed -i -e "/$IP_UNBLOCK/d" /etc/hosts.deny
sed -i -e "/^$IP_UNBLOCK/d" /var/lib/denyhosts/hosts
sed -i -e "/^$IP_UNBLOCK/d" /var/lib/denyhosts/hosts-restricted
sed -i -e "/^$IP_UNBLOCK/d" /var/lib/denyhosts/hosts-root
sed -i -e "/^$IP_UNBLOCK/d" /var/lib/denyhosts/hosts-valid
sed -i -e "/$IP_UNBLOCK/d" /var/lib/denyhosts/users-hosts
sed -i -e "/^$IP_UNBLOCK/d" /var/lib/denyhosts/hosts-root
sed -i -e "/refused connect from $IP_UNBLOCK/d" /var/log/auth.log
sed -i -e "/from $IP_UNBLOCK port/d" /var/log/auth.log
iptables -D INPUT -s "$IP_UNBLOCK" -j DROP
ufw reload
systemctl start denyhosts
并在安装denyhosts之前运行它
echo "All:" $(last -i | grep -v '0.0.0.0' | grep 'root' | head -1 | awk '{print $3}') >> /etc/hosts.allow
答案 8 :(得分:0)
什么都没做,只有Oleksandr Shmyheliuk回答
使用以下两个命令
iptables -L -n -v | grep 49.33.135.137
如果有输出,则使用以下命令
iptables -D INPUT -s 49.33.135.137 -j DROP