当你通过SSHconfigurationiptables或SSH,并且数据中心距离数千公里远(并且让某人插入KVM很困难时),有什么标准的做法可以防止自己locking?
有一个类似的问题通过SSHconfigurationiptables而不被locking?
我在这里发表我在上一个问题中给出的提示:
1)我备份旧的iptablesconfiguration文件:
cp /etc/sysconfig/iptables /etc/sysconfig/iptables.bak
2)尝试新的设置之前,执行此命令以确保您可以连接回来,如果在新的设置中的东西locking你(基本上它取代旧规则5分钟后):
echo "mv /etc/sysconfig/iptables.bak /etc/sysconfig/iptables && service iptables restart" | at now + 5min
3)现在你可以安全地修改iptables规则。 如果有什么不好,你可以在5分钟之内回来。
如果您需要修改SSHconfiguration,例如在/etc/ssh/sshd_config :在其他terminal中保留一个会话。 这通常会保持打开状态,当然你也可以使用类似于@ shardan的SSHconfiguration文件的技巧。
另一种确保访问的方法是在远程服务器上使用ssh的-R标志:
/usr/bin/ssh -R 55555:localhost:22 [email protected]
从your.otherserver.com您现在可以使用以下方式login到远程机器:
ssh localhost -p 55555
为了确保我没有被locking5分钟以上,我运行了一个在远程服务器上运行以下shell脚本的cron作业:
#! /bin/sh GREPSSH=$(ps ax|grep serverkey|awk -F ' ' '{print $1}') if [ "$GREPSSH" -eq NULL ] then echo "no sshlink \n" /usr/bin/ssh -nNT -i ~/.ssh/serverkey -R 55555:localhost:22 -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes [email protected] & else echo $GREPSSH exit 1 fi
这个脚本:
我发现这是回到远程机器的一个有用的工具:〜)