Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apt-get proxy: Permission denied

I am trying to make a bash script that will set up a proxy on my computer running ubuntu studio. This [1] tells me that I should set up the proxies for apt-get and Update Manager by creating a file 95proxies in /etc/apt/apt.conf.d/.

the problem is when I run this code.

sudo echo "Acquire::http::proxy "http://myproxy.server.com:8080/";
Acquire::ftp::proxy "ftp://myproxy.server.com:8080/";
Acquire::https::proxy "https://myproxy.server.com:8080/";
" > /etc/apt/apt.conf.d/95proxies

I get:

bash: /etc/apt/apt.conf.d/95proxies: Permission denied

I was able to create the file with touch by

sudo touch /etc/apt/apt.conf.d/95proxies

but when I go to put data in the file I still get the error message above.

[1] https://askubuntu.com/questions/150210/how-do-i-set-systemwide-proxy-servers-in-xubuntu-lubuntu-or-ubuntu-studio

like image 940
Andrew Pullins Avatar asked Jan 25 '26 14:01

Andrew Pullins


1 Answers

This is essentially the same problem as described in "How do I use sudo to redirect output to a location I don't have permission to write to?". That is, even though you're running echo with sudo, it's not echo that's writing to the file, it's your shell, and your shell doesn't have permission to write to that file.

One possible solution would be to use sudo with a program such as tee that actually does write to the file itself rather than relying on the shell:

echo "Acquire::http::proxy \"http://myproxy.server.com:8080/\";" | sudo tee /etc/apt/apt.conf.d/95proxies > /dev/null

For more possible solutions to this problem, see How do I use sudo to redirect output to a location I don't have permission to write to?

like image 79
Ajedi32 Avatar answered Jan 28 '26 12:01

Ajedi32



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!