know_hosts与端口

在gitlab runner写自动发布脚本的时候,有如下这段代码,git clone一直显示没有权限,然而使用相同密钥的宿主机是没有问题的,只有而runner容器可以ssh却不能clone。

1
2
3
4
5
6
7
8
9
10
build:
stage: build
image:
name: docker-executor:latest
pull_policy: if-not-present
before_script:
- source /app/setup.sh
script:
- ssh root@10.0.24.9 "cd /app/hexo && git pull"
- git clone ssh://git@10.0.24.9:7003/root/chlm-common.git

经过一番折腾,检查了下宿主机know_hosts文件,发现了端倪,git连接的地址加上了端口,所以know_host需要添加一个带端口的记录。

1
2
3
4
5
6
7
8
9
10
11
12
13
build:
stage: build
image:
name: docker-executor:latest
pull_policy: if-not-present
before_script:
- source /app/setup.sh
script:
- ssh root@10.0.24.9 "cd /app/hexo && git pull"
# 添加端口的know_hosts
- ssh-keyscan -p 7003 10.0.24.9 >> ~/.ssh/known_hosts
- git clone ssh://git@10.0.24.9:7003/root/chlm-common.git
- git clone ssh://git@10.0.24.9:7003/root/chlm-redis.git