linux - apt-get 代理 : Permission denied

标签 linux bash ubuntu proxy xfce

我正在尝试制作一个 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

但是当我将数据放入文件时,我仍然收到上面的错误消息。

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

最佳答案

这基本上与“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/

相关文章:

ubuntu - 安装时选择puppet客户端版本-Ubuntu

c - 使用c从linux中的串口获取二进制数据

linux - 在 bash 脚本中传递标志失败

bash - sed中变量之间的换行符

bash - bash脚本ip主机

windows - 为什么 d3 图表中的日期在 ubuntu 的 firefox 中显示为凌晨 1 点,而在 windows 的 firefox 中显示为日期和日期?

linux - 在不同的脚本/终端中使用 wlan0 或 eth0

linux - Bash 脚本 - 根据模板转换时间

Linux阿尔卑斯: xfce4 and unsatisfiable constraints

python - 无法在 Ubuntu 的 Python 环境中运行 Jupyter Notebook