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





沒有留言:

張貼留言

只要點兩下就能利用彰化縣EIP系統學生帳號CSV產出建立Google Classroom 學生總表

          彰化縣數位學習師生單一帳號系統(EIP=Enterprise Information Portal)於2025年7月7日正式啟用。我要如何利用EIP系統學生帳號CSV來建立Google Classroom 後,將各班的學生加入。或是給老師一張學生帳號總表,讓老...