Debris 20190530

Problem fixed

Conda 修改 channel

1
2
3
4
5
6
nano ~/.condrc
source ~/.condrc
conda config --add channels xxxx
conda config --remove channels xxxx

## example: conda config --remove channels 'intel'

Conda 保存于环境保存与重建

1
2
conda env export > environment.yaml
pip freeze > requirement.txt
1
conda env create -f environment.yaml

SSH,SCP穿越跳板机

  1. 直接编辑 ~/.ssh/config 文件, 增加ProxyCommand选项

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Host gateway
    HostName gatewayhost
    User gateway_user

    Host target.machine #主机别名,也可写成目标服务器IP,可使用通配符,如:Host 10.208.*
    HostName target.machine #目标机域名或IP地址
    User targetuser #SSH用户名
    Port 22 #SSH端口
    ProxyCommand ssh -q -W %h:%p gateway
    IdentityFile ~/.ssh/id_rsa #登陆跳板机的私钥所在位置,如默认位置可不用显示指定
  2. 用ssh-keygen在本机生成private key and public key

1
ssh-keygen ## in local host
  1. copy the public key to authorized_keys in gateway and target.machine
1
2
3
cat ~/.ssh/id_rsa.pub  ## in local host

nano ~/.ssh/authorized_keys ## in gateway and target.machine, add the content got above
  1. 现在,只需要通过下面这样简单的语句登陆远程计算机:

    1
    ssh target.machine

还可以直接SCP过去,跳板机完全透明:

1
scp ToCopy.txt target.machine:~

  1. 使用 command
  • 直接跳到远程计算机

    1
    ssh -o ProxyCommand="ssh -q -W %h:%p user@jumphost" lmx@target.machine
  • 拷贝文件到远程计算机

    1
    scp -o ProxyCommand="ssh -q  -W %h:%p user@jumphost" lmx@target.machine:~/rdsAgent .
  • 在远程计算机执行命令

    1
    ssh -o "ProxyCommand ssh -q  -W %h:%p user@jumphost" lmx@target.machine 'ip a'

本地配置多个 ssh key

  1. 为github 生成 ssh key

    1
    ssh-keygen -t rsa -C "your_mail@example.com" -f github_rsa
  2. 为gitlab 生成 ssh key

    1
    ssh-keygen -t rsa -C "your_mail@example.com" -f gitlab_rsa
  3. 修改.ssh/config

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    # github.com
    Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github_rsa

    # gitlab.company.com
    Host gitlab.company.com
    HostName gitlab.company.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/company_rsa
  4. 如果需要代理,给github设置proxy

    1
    2
    git config --global http.proxy 'socks5://127.0.0.1:1080'
    git config --global https.proxy 'socks5://127.0.0.1:1080'
1
2
3
4
5
6
7
8
// edit ~/.ssh/config   add the lines blow
host github.com
hostname ssh.github.com
user git
port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_zrc
proxycommand socat - PROXY:<Ip>:%h:%p,proxyport=<Port>
  1. Test
    1
    ssh -T git@github.com

Skills

对象的深浅拷贝

1
2
3
4
5
6
7
8
9
tmp = []
all_pos = []
for i in range(100):
tmp.append(i)
if len(tmp) % 10 == 0:
all_pos.append(tmp)
#print(id(tmp) == id(all_pos[-1])) # True
tmp[:] = [] ## 清空当前对象
print(all_pos) # [[],[],[]]
1
2
3
4
5
6
7
8
9
tmp = []
all_pos = []
for i in range(100):
tmp.append(i)
if len(tmp) % 10 == 0:
all_pos.append(tmp)
#print(id(tmp) == id(all_pos[-1])) # True
tmp = [] ## 生成新的对象
print(all_pos) # [[ 1,2,3...],[11,12,...],]
Donate article here