作者dyoll (lloyd huang)
看板Linux
標題Re: [問題] 如何預先輸入?
時間Sun Dec 27 18:33:23 2009
※ 引述《feynman511 (noonee)》之銘言:
: 假設我現在做的動作裡面有些動作需要手動輸入
: 例如輸入密碼 請問要怎麼寫?
: sudo apt-get update
: sudo apt=get upgrade
: 可是在輸入第一行後系統會跟我要密碼
: 那我該怎麼寫才能讓密碼自動輸入?
====>
其實換個角度想,也許你要的是如何使用 sudo 不用輸入 passwd
如果你是這樣問的話,那我會回答
# editor /etc/sudoers
feynman ALL=PASSWD: ALL
不過你問的是 -- 如何自動輸入密碼
那我的回答會是
$ ls -l sudo_apt-get_update.exp
-rwxr-xr-x
$ cat sudo_apt-get_update.exp
#!/usr/bin/expect
spawn sudo apt-get update
expect "password"
send "YOUR_PASSWORD\r"
expect "$"
把密碼留在檔案裏真的會比較好嗎?
But The Way: 我特別去翻 sudoers man page,找出每次都會問密碼的設定
# cat /etc/sudoers
Defaults env_reset, timestamp_timeout=0
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.127.60.21
推 mshx:若把密碼留在檔案內,又沒控制好檔案權限的話 12/27 19:53
→ mshx:grep -rn password /就可以找到一堆東西囉 12/27 19:54