一、apt
1,临时设置代理
$ sudo apt-get -o Acquire::http::proxy="proxyaddress:port/" update(或者要下载的软件包名称)
$ sudo apt-get -o Acquire::https::proxy="proxyaddress:port/" update(或者要下载的软件包名称)
$ sudo apt-get -o Acquire::ftp::proxy="proxyaddress:port/" update(或者要下载的软件包名称)
$ sudo apt-get -o Acquire::socks::proxy="proxyaddress:port/" update(或者要下载的软件包名称)
以上四种根据要访问的网址选择一种,一般是http、https
2,永久设置代理
$ vim /etc/apt/apt.conf.d/10proxy #这个文件正常不存在,会新建一个
将以下内容写入10proxy中:
Acquire::http::proxy "proxyaddress:port/";
Acquire::https::proxy "proxyaddress:port/";
Acquire::ftp::proxy "proxyaddress:port/";
Acquire::socks::proxy "proxyaddress:port/";
然后保存。
注意:
1,分号不要漏掉
2,将proxyaddress:port/换为自己的代理地址和端口号
二、yum
1,临时设置代理
export http_proxy=“http://代理服务器IP:端口号”
执行上述命令就可以了
2,永久设置代理
$ sudo vim /etc/yum.conf
将以下内容添加到/etc/yum.conf中
proxy=协议://代理服务器地址:端口 # (如:proxy=http://192.168.9.9:8080)
三,pip
1,临时设置代理
$ pip install XXX --proxy=proxyaddress:port
2,永久设置代理
打开相关配置文件:
$ vim /etc/profile
将下面写入写入到文件最后
export http_proxy='http://代理服务器IP:端口号'
export https_proxy='http://代理服务器IP:端口号'
然后执行
$ source /etc/profile
四,conda
1,临时设置代理
暂无
2,永久设置代理
$ vim ~/.condarc
将以下内容添加到文件中
channels:
#如果要添加国内镜像,在-defaults前加入【-国内源,形如 -http://ali.com】
- defaults
show_channel_urls: True
allow_other_channels: True
proxy_servers:
http: http://username:password@ip:port
https: https://username:password@ip:port
#如果代理有账号和密码的话按上述形式写,如果没有,写成http://ip:port和https://ip:port
ssl_verify: false
use_pip: true
五,wget
1,临时设置代理
$ wget http://www.baidu.com/ -e use_proxy=yes -e http_proxy=代理服务器IP:端口号
$ wget http://www.baidu.com/ -e use_proxy=yes -e https_proxy=代理服务器IP:端口号
2,永久设置代理
$ vim ~/.wgetrc
将以下内容写入
http_proxy = http://代理服务器IP:端口号/
https_proxy = http://代理服务器IP:端口号/
ftp_proxy = http://代理服务器IP:端口号/
use_proxy = on
六,curl
1,临时设置代理
curl -x 代理服务器IP:端口号 http://www.baidu.com/
2,永久设置代理
$ vim ~/.curlrc
写入以下内容:
proxy=代理服务器IP:端口号
七,git
1,临时设置代理
$ git config --global http.proxy 代理服务器IP:端口号 #服务器重启就会失效
$ git config --global --unset http.proxy #不用重启机器取消代理
2,永久设置代理
$ sudo vim ~/.bashrc
将下面内容写入
gp=" --config http.proxy=代理服务器IP:端口号"
然后
$ source ~/.bashrc
八,ssh
1,临时设置代理
$ ssh -o "ProxyCommand=nc -X 5 -x 代理服务器地址:端口号 %h %p" 服务器用户名@服务器ip地址
2,永久设置代理
首先安装Corkscrew:
$ sudo apt-get update
$ sudo apt-get install corkscrew
然后添加修改ssh配置:
$ vim ~/.ssh/config #如果可能不存在这个路径,那就手动创建
将以下内容写入配置文件中保存
Host *
ProxyCommand corkscrew 代理服务器地址 端口号 %h %p
九,scp
1,临时设置代理
$ scp -o "ProxyCommand=nc -X connect -x 代理服务器地址:端口号 %h %p" -r 要传输的文件名 服务器用户名@服务器ip地址:文件要拷贝的路径 #如果不是文件夹,可去掉-r
2,永久设置代理
与ssh操作一样
上述内容有可能有不对的地方,欢迎大家留言指正!!!
Done!