.ssh/config 常用配置

不用每次都 -i 指定密钥,且避免连接自动断开

ControlMaster auto
ControlPath ~/.ssh/connection-%r@%h:%p
ControlPersist 4h
ServerAliveInterval 6
ServerAliveCountMax 20
Compression yes

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github

Host hangj
Hostname mydomain.name
User hangj
IdentityFile ~/.ssh/hk

然后ssh hangj就可以连上我的服务器拷贝文件
scp file.txt hangj:~/
scp hangj:~/file.txt ./

简单,高效,省心,关键还防秃~~~

管理多个 github 的 deploy key

在 GitHub 仓库设置好 webhooks,当有新的 push 时,自动发一个 POST 到我的 web 服务器然后 web 服务器调用一个 shell 脚本自动 pull 最新代码,并重启服务
服务器上只需要 pull 代码,所以没必要专门给它配置一个 robot 用户,这个时候可以用 deploy key,给这个 key 设置好 pull 的权限
把 key 文件保存好,然后在 ~/.ssh/config 文件加上
Host myproject1
HostName github.com
User git
IdentityFile ~/.ssh/github_deploy_myproject1

然后到你的仓库目录下(hangj 是我的用户名)
$ git remote set-url origin git@myproject1:hangj/myrepo.git
$ git remote -v

命令行里的myproject1就是 ~/.ssh/config 里的 Host, hangj 是我的用户名
指定 Host,是为了方便管理多个仓库,每个仓库用自己的 deploy key,不会乱

网络

网络配置方式

静态指定
命令——
ifconfig, route, netstat
注意:立即生效
启用混杂模式: [-]promisc

ip
ss
tc
图形化——
nmtui
system-config-network-tui
setup
配置文件
动态分配:
DHCP:
Dynamic Host Configuration Protocol

路由管理命令查看:route-n
添加:route add
route add [-net|-host] target [netmask Nm] [gw Gw] [[dev] If]
目标:192.168.1.3 网关:172.16.0.1
route add -host 192.168.1.3 gw 172.16.0.1 dev eth0
目标:192.168.0.0 网关:172.16.0.1
route add -net 192.168.0.0 netmask 255.255.255.0 gw 172.16.0.1 dev eth0
route add -net 192.168.0.0/24 gw 172.16.0.1 dev eth0
route add default (defaule <=> -net 0.0.0.0 netmask 0.0.0.0)
网卡安装卸载(免重启使网络设置生效)
接口命名方式:CentOS6以太网:eth[0,1,2…]
ppp: ppp[0,1,2…]
网络接口识别并命名相关的udev配置文件:
/etc/udev/rules.d/70- persistent-net.rules
查看网卡:
dmesg | grep -i eth
ethtool -i etho
卸载网卡驱动:
modprobe -r e1000
rmmod e1000
装载网卡驱动:
modprobe e1000

linux 开启路由转发功能

linux 默认到达自己的数据包如果不是自己的就会丢弃
techo 1 > /proc/sys/net/ipv4/ip_forward