Linux 修改ssh链接之后的提示语 Welcome

可在/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~]#

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值