2021年3月4日 星期四

如何在linux shell 交互環境下,自動填入密碼

 


1.安裝expect
sudo apt-get install expect

2.建立test.exp
$sudo pico test.exp

目的:利用帳號 webadmin 密碼 demo1234 從192.168.1.150 用ssh連線到 192.168.1.157

檔案名稱:test.exp
檔案內容
#!/usr/bin/expect          
set user "webadmin"          
set pwd "demo1234"
set host "192.168.1.157"

set timeout -1
spawn ssh -p 22 $user@$host
expect {
    "password: " {send "$pwd\r"}
}
expect "]*"                
send "touch /home/webadmin/aa.txt\r"
expect "]*"
send "echo hello world >> /home/webadmin/aa.txt\r"
expect "]*"             
interact

3.變更權限
$sudo chmod 777 test.exp

4.執行 test.exp
$sudo expect test.exp





沒有留言:

張貼留言

想修改 chcweb 出現的問題解決集

系列文章: 1. Ubuntu 24.04 安裝 chcweb 專案的過程記錄 2. Ubuntu 24.04 安裝 laravel 5.7 的過程記錄 3. laravel 5.7 初始相關設定與注意事項 4. 想修改 chcweb 出現的問題解決集   問題一: Unexpe...