欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

如何使用 shell 命令从钥匙串中删除密码? 移除wifi密码 忘记wifi密码 有大用 有大大用

见下面的红色字部分

How to delete a password from keychain with a shell command?如何使用 shell 命令从钥匙串中删除密码?

Ask Question  问问题 Asked 11 年, 5 个月前 问Modified 8 years, 4 months ago    修改 8 年, 4 个月前Viewed     7k times  浏览了 7k 次 2

I wanted to make a shell script that connects to a hidden wireless network on my macbook pro by creating a network. However, I only want to connect to that network when I want to and to prevent airport from connecting automatically I'll have to delete the network's password from keychain.我想制作一个 shell 脚本,通过创建网络连接到我的 macbook pro 上的隐藏无线网络。但是,我只想在需要时连接到该网络,并且为了防止机场自动连接,我必须从钥匙串中删除网络密码。

So far I have: 到目前为止,我有: 

networksetup -setairportnetwork en1 $ssid $networkpassword
networksetup -removepreferredwirelessnetwork en1 $ssid

解释解释解释


Im also aware that in OSX 10.7 the security     command can modify the keychain.我还知道在 OSX 10.7 中,该security命令可以修改钥匙串。

Anyway I would appreciate any help someone can give me. I'm also willing to use applescript or something else if it works. Thank you.无论如何,我将不胜感激有人能给我的任何帮助。如果可以的话,我也愿意使用 applescript 或其他东西。谢谢。

edited Dec 10, 2015 at 21:35    编辑日期: 2015年12月10日 21:35    asked Jan 21, 2013 at 4:23    已问 Jan 21, 2013 at 4:23fredie mathews's user avatarfredie mathews 弗雷迪·马修斯 41 41 1 silver badge6 bronze badges

  • You should post your solution as an answer, not edit it into the question.您应该将解决方案作为答案发布,而不是将其编辑到问题中。– Barmar CommentedJan 22, 2013 at 8:50

Add a comment 添加评论 

1 Answer  1 个回答   正确答案

2

I figured it out. The command I used is:我想通了。我使用的命令是:

sudo security delete-generic-password -l $ssid "/Library/Keychains/System.keychain"
sudo security delete-generic-password -l $ssid    #后面这个路径可以不用吧 比如( "/Library/Keychains/System.keychain" 或 "~/Library/Keychains/ogin.keychain-db" )
解释解释解释


sudo was needed because this keychain is located in the systems library. security     also contains a lot more delete and useful commands and you can specify how you want to indicate the location in this command.需要 sudo,因为此钥匙串位于系统库中。security还包含更多删除和有用的命令,您可以指定如何在此命令中指示位置。


edit: I was having some trouble using this command and went back and learned I could use another command to not remember the network at all which I would have used before if I had found it. With this option you can do a wealth of things with your adapter along with the networksetup option.编辑:我在使用这个命令时遇到了一些麻烦,然后回去了解到我可以使用另一个命令来完全不记得网络,如果我找到它,我以前会使用它。使用此选项,您可以使用适配器以及 networksetup 选项执行大量操作。

Here is my final script which first runs as root. then it changes the system preferences to not remember new networks. Then it disconnects from any current networks. Then it adds the new network. Lastly, it makes the system remember new wifi networks.这是我的最终脚本,它首先以 root 身份运行。然后,它会更改系统首选项以不记得新网络。然后,它会断开与任何当前网络的连接。然后,它会添加新网络。最后,它使系统记住新的wifi网络。

sudo -i
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport prefs RememberRecentNetworks=NO
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -Z
networksetup -setairportnetwork en1 $ssid $password
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport prefs RememberRecentNetworks=YES

解释解释解释解释


edited Dec 10, 2015 at 21:37answered Jan 23, 2013 at 6:44fredie mathews's user avatarfredie mathews411 silver badge6 bronze badgesAdd a comment 添加评论 

Your Answer   

来自  https://stackoverflow.com/questions/14432511/how-to-delete-a-password-from-keychain-with-a-shell-command                


           


普通分类: