【发布时间】:2015-09-15 09:22:00
【问题描述】:
我在 Ubuntu Linux 上使用 GIT 作为自动构建过程的一部分。因为是自动化构建过程,所以最好将所有配置都放在版本控制中,这样配置发生变化时我就不用登录每个构建代理了。
为了让它工作,我有一个私钥(具有只读 repo 访问权限)和一个 known_hosts 文件签入到版本控制中。
我将 HOME 环境变量设置为我的版本控制 (build/ssh_home) 中的一个位置,以允许 GIT 找到我的 known_hosts 文件 (build/ssh_home/.ssh/known_hosts)。
我使用以下命令“激活”私钥并从 GIT 中提取。 “git clone”步骤类似。
ssh-agent bash -c "echo $HOME; ssh-add '${deploymentKey}' >/dev/null 2>&1; git pull ${repository} --quiet"
这适用于 Windows。但是,在 Ubuntu Linux 上,这还不够。
“HOME”环境变量设置如下(在 bash 脚本中)
export HOME=`pwd`/build/ssh_home
但是,它显然没有使用正确的 known_hosts 文件,它仍在尝试使用 ~/.ssh/known_hosts 中的文件,以下消息中引用的路径证明了这一点。
The authenticity of host 'bitbucket.org (131.103.20.168)' can't be established.
RSA key fingerprint is 97:8c:1b:f2:6f:14:6b:5c:3b:ec:aa:46:46:74:7c:40.
Are you sure you want to continue connecting (yes/no)? yes
Failed to add the host to the list of known hosts (/home/myusername/.ssh/known_hosts).
如何让 GIT (SSH) 使用特定位置(不在我的主目录中)的 known_hosts 文件?
编辑:
我的“build/ssh_home”目录的权限(在 cmets 中请求)
ls -la build/ssh_home
total 16
drwx------ 3 ben ben 4096 Jun 18 10:52 .
drwxrwxr-x 39 ben ben 4096 Jun 18 10:52 ..
-rw------- 1 ben ben 209 Jun 18 10:52 readme.txt
drwx------ 2 ben ben 4096 Jun 18 10:52 .ssh
build/ssh_home/.ssh 的权限
ls -la build/ssh_home/.ssh
total 12
drwx------ 2 ben ben 4096 Jun 18 10:52 .
drwx------ 3 ben ben 4096 Jun 18 10:52 ..
-rw------- 1 ben ben 2402 Jun 18 10:52 known_hosts
我的“~/.ssh”目录的权限(在 cmets 中请求)
myusername@myhostname:~$ ls -la ~/.ssh
total 24
drwxr-xr-x 2 root root 4096 Jun 29 10:28 .
drwxr-xr-x 16 ben ben 4096 May 21 15:39 ..
-rw-r--r-- 1 root root 427 May 19 11:27 authorized_keys
-rw------- 1 root root 1679 May 19 11:27 bitbucket
-rw-r--r-- 1 root root 398 May 19 11:27 bitbucket.pub
-rw-r--r-- 1 root root 63 May 19 11:27 config
【问题讨论】:
-
@Makoto 我也会添加那个。但是,我的关键问题是我不想在构建系统上搞乱
~/.ssh/known_hosts。我想在版本控制中维护所有配置。