我正在尝试制作一个 bash 脚本,它将在我运行 ubuntu studio 的计算机上设置代理。这个 [1] 告诉我应该通过在/etc/apt/apt.conf.d/中创建文件 95proxies 来为 apt-get 和更新管理器设置代理。
问题出在我运行这段代码的时候。
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
我得到:
bash: /etc/apt/apt.conf.d/95proxies: Permission denied
我能够通过触摸创建文件
sudo touch /etc/apt/apt.conf.d/95proxies
但是当我将数据放入文件时,我仍然收到上面的错误消息。
最佳答案
这基本上与“How do I use sudo to redirect output to a location I don't have permission to write to?”中描述的问题相同。也就是说,即使您使用 sudo
运行 echo
,写入文件的不是 echo
,而是您的 shell,而您的 shell没有写入该文件的权限。
一个可能的解决方案是将 sudo
与诸如 tee
之类的程序一起使用,该程序实际上会写入文件本身,而不是依赖于 shell:
echo "Acquire::http::proxy \"http://myproxy.server.com:8080/\";" | sudo tee /etc/apt/apt.conf.d/95proxies > /dev/null
有关此问题的更多可能解决方案,请参阅 How do I use sudo to redirect output to a location I don't have permission to write to?
关于linux - apt-get 代理 : Permission denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22877367/