從 Command Line 存取 Keychain 的方法

[華語, cmn-Hant-TW]

其實主要是說在寫 shell scripts 的時候會比較方便啦,這樣總比直接把密碼之類的存在檔案裡來得安全些。 在 shell 中可以用 service 對 Keychain 做存取,可以設很多不同的條件來取得 Keychain 上的資料。而如果要直接拿到密碼,這樣打就可以了:

 security -q find-internet-password -s $name -g 2>&1  | grep password | cut -d \" -f 2 

然後會有視窗跳出來提示說有程式想抓資料,選確定即可。
要注意的是這樣真的就會把密碼挖出來,所以使用上務必小心就是了。

Leave a Reply

Your email address will not be published. Required fields are marked *