Linux自动输入密码登录用户

每次进去Linux系统,都有切换root用户,输入密码很麻烦,所以就写了一个小脚本,自动输入密码,登录到root用户,

1,首先检查一些是否安装了expect

root@wuzs:/home/wuzs# whereis expect                                                     expect: /usr/bin/expect /usr/share/man/man1/expect.1.gz

如果没有需要安装一下

apt install expect

2,代码如下

root@wuzs:/home/wuzs# cat suroot.sh                                                       #!/usr/bin/expect
set timeout 30
spawn su root
expect "Password:"
send "********\r"#此处输入密码,\r回车
interact
root@wuzs:/home/wuzs#

参考连接:https://www.cnblogs.com/lixigang/articles/4849527.html

猜你喜欢

转载自www.cnblogs.com/mrwuzs/p/11335868.html