Redmi AX6000 固化ssh

从telnet开启的ssh,路由器重启会失效,添加一个开启自动运行的脚本,来实现自动开启ssh。如果恢复出厂设置或重新刷机后需要重新添加.

mkdir /data/auto_ssh && cd /data/auto_ssh
touch auto_ssh.sh
chmod +x auto_ssh.sh

创建auto_ssh.sh文件,使用vi输入下面的内容并保存

#!/bin/sh

host_key=/etc/dropbear/dropbear_rsa_host_key
host_key_bk=/data/auto_ssh/dropbear_rsa_host_key

if [ -f $host_key_bk ]; then
    ln -sf $host_key_bk $host_key
fi

channel=`/sbin/uci get /usr/share/xiaoqiang/xiaoqiang_version.version.CHANNEL`
if [ "$channel" = "release" ]; then
    sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear
    /etc/init.d/dropbear restart
fi

if [ ! -s $host_key_bk ]; then
    i=0
    while [ $i -le 30 ]
    do
        if [ -s $host_key ]; then
            cp -f $host_key $host_key_bk 2>/dev/null
            break
        fi
        let i++
        sleep 1s
    done
fi

将auto_ssh写入固化

uci set firewall.auto_ssh=include
uci set firewall.auto_ssh.type='script'
uci set firewall.auto_ssh.path='/data/auto_ssh/auto_ssh.sh'
uci set firewall.auto_ssh.enabled='1'
uci commit firewall

文章作者: Payne Fu

文章链接: http://beyondkmp.com/2023/03/05/ax6000-ssh/

posted @ 2023-07-29 15:22  ren_miruu  阅读(639)  评论(0编辑  收藏  举报