每次進去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#