可在/etc/rc.local文件中增加执行以下脚本的逻辑,这样的话,每次reboot机器之后,会根据脚本重设提示语
# Modify login prompt information
ssh_port=50022
ip=`/sbin/ifconfig | grep inet |grep -v inet6 |grep -v '127.0.0.1'|awk -F' ' '{print $2}'`
arr=($ip)
cli=""
len=${#arr[@]}
len_1=$len
if [ $len_1 -eq 0 ];then
rm -rf /etc/issue
rm -rf /etc/motd
touch /etc/issue
touch /etc/motd
chmod 666 /etc/issue
chmod 666 /etc/motd
echo "All network cards are closed"
echo "All network cards are closed" >>/etc/issue
echo "All network cards are closed" >>/etc/motd
exit
else
last=${arr[$len-1]}
if [[ "$len" -ge 1 ]];then
for s in ${arr[@]}
do
if [ "$s" == "$last" ];then
cli="$cli -p $ssh_port root@$s "
else
cli="$cli -p $ssh_port root@$s or"
fi
done
else
cli="-p $ssh_port root@${arr[0]}"
fi
# Display before Login
rm -rf /etc/issue
touch /etc/issue
chmod 666 /etc/issue
echo "Welcome!" >> /etc/issue
echo "You can manage it by: " >> /etc/issue
echo "ssh $cli to access the Terminal" >> /etc/issue
echo " " >> /etc/issue
# Display after login
rm -rf /etc/motd
touch /etc/motd
chmod 666 /etc/motd
echo "Welcome!" >> /etc/motd
echo "You can manage it by: " >> /etc/motd
echo "ssh $cli to access the Terminal" >> /etc/motd
echo " " >> /etc/motd
fi
ssh接入后,效果如下:
Connecting to 192.168.1.24:50022...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last login: Thu Nov 17 00:23:03 2022 from 192.168.1.23
Welcome!
You can manage it by:
ssh -p 50022 root@192.168.1.24 to access the Terminal
[root@saggitarxm~]#