Network proxy setup in terminal I am trying to create a bash script that will update the mac's proxy settings and a few other places when a user changes their password every 60 days. So far I am trying to use this command for the proxy

networksetup -setwebproxy wi-fi proxy.example.com 8080 on "$USER" "$NewPassword"


but when I run the command after the proxy has been set up, it gives an error.

networksetup[32852:1867937] error -25299 attempting to create account and password for proxy: proxy.example.com:8080


The error will only shows up when the username and password have been previously set up, but if I delete the username and password from the GUI, then run the command it will setup the authentication.

Anyone have any ideas?
You need to delete the proxy password programmatically, something like - 

security delete-internet-password -s $PROXY
networksetup -setwebproxy Ethernet $PROXY 8080 on $USER $PASSWORD


Here, the -s tells it to delete the internet password that has the server set as proxy.example.com

Once it's deleted you can recreate the web proxy entries.

If you want to find the passwords to test before deleting, you can do the following, and confirm you get only one entry. You can also set a comment (use KeyChain Access), and confirm it shows up in the icmt field:

security find-internet-password -s 'proxy.example.com'
keychain: "/Users/alex/Library/Keychains/login.keychain-db"
version: 512
class: "inet"
attributes:
0x00000007 &lt;blob&gt;="proxy.example.com"
0x00000008 &lt;blob&gt;=&lt;NULL&gt;
"acct"&lt;blob&gt;="username"
"atyp"&lt;blob&gt;=&lt;NULL&gt;
"cdat"&lt;timedate&gt;=0x32303139303231383032343431305A00  "20190218024410Z\000"
"crtr"&lt;uint32&gt;=&lt;NULL&gt;
"cusi"&lt;sint32&gt;=&lt;NULL&gt;
"desc"&lt;blob&gt;=&lt;NULL&gt;
"icmt"&lt;blob&gt;=&lt;NULL&gt;
"invi"&lt;sint32&gt;=&lt;NULL&gt;
"mdat"&lt;timedate&gt;=0x32303139303231383032343632395A00  "20190218024629Z\000"
"nega"&lt;sint32&gt;=&lt;NULL&gt;
"path"&lt;blob&gt;=&lt;NULL&gt;
"port"&lt;uint32&gt;=0x00001F90
"prot"&lt;blob&gt;=&lt;NULL&gt;
"ptcl"&lt;uint32&gt;="htpx"
"scrp"&lt;sint32&gt;=&lt;NULL&gt;
"sdmn"&lt;blob&gt;=&lt;NULL&gt;
"srvr"&lt;blob&gt;="proxy.example.com"
"type"&lt;uint32&gt;=&lt;NULL&gt;