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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM