写在前面
有时候办公会用到Ubuntu虚拟机做测试,可是仅仅使用系统设置的代理,浏览器能够上网,无法安装需要的各种服务和第三方包,百度后得到方法,可以让apt也走代理。
方法
sudo vim /etc/apt/apt.conf.d/proxy.conf
贴入以下内容:
#注意修改用户名和密码、服务器和端口
Acquire::http::Proxy "http://user:password@proxy.server:port/";
Acquire::https::Proxy "http://user:password@proxy.server:port/";
为git配置代理:
使用如下命令:
#socks5
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
#http
git config --global http.proxy 'http://127.0.0.1:1080'
git config --global https.proxy 'http://127.0.0.1:1080'
取消代理:
git config --global --unset http.proxy
git config --global --unset https.proxy
只对github设置代理:
#socks5
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
#http
git config --global http.https://github.com.proxy http://127.0.0.1:1080
取消代理:
git config --global --unset http.https://github.com.proxy
如果代理需要验证,则写为如下形式:
http://username:password@host:port
为ssh配置代理
socks:
#socks4
ssh -p port -o "ProxyCommand=nc -X 4 -x proxyhost:proxyport %h %p" username@ipaddress
#socks5
ssh -p port -o "ProxyCommand=nc -X 5 -x proxyhost:proxyport %h %p" username@ipaddress
#https
ssh -p port -o "ProxyCommand=nc -X connect -x proxyhost:proxyport %h %p" username@ipaddress
http:
安装corkscrew:
sudo apt install corkscrew
创建配置文件:
sudo vim ~/.ssh/config
贴入以下内容:
#*代表对所有主机执行代理
Host *
ProxyCommand corkscrew http-proxy.example.com 8080 %h %p
或者对部分主机执行代理:
Host aliyun
Hostname 1.1.1.1
User ubuntu
ProxyCommand corkscrew http-proxy.example.com 8080 %h %p
配置ssh免密登录
生成密钥对:
cd ~/.ssh
ssh-keygen -t rsa -P '' -f id_rsa
ls发现多了两个文件,将id_rsa.pub中的内容(以文本方式打开)贴进远程主机的authorized_keys文件里
连接远程主机:
ssh user@host
编辑目标文件:
sudo vim ~/.ssh/authorized_keys
将公钥内容粘贴进去即可,如有多个请换行输入