【发布时间】:2020-05-19 18:29:52
【问题描述】:
操作系统:带有 Windows 10 虚拟机的 Ubuntu
目标:在 Windows 10 虚拟机上设置 git bash,并使用 ssh 密钥与私有 Bitbucket 一起使用。
概述: 将 SSH 密钥生成到非默认位置以使用 git bash 不起作用。一个尝试的解决方案是创建默认位置并将密钥移动到该位置进行测试。我不太了解默认位置是如何生成的,或者 git bash 如何搜索 sshkey 以与 bitbucket 进行比较。我怀疑网络驱动器/IT 可能会影响问题,但不知道要问的正确问题。步骤和细节如下。是的,ssh 密钥已添加到 bitbucket 帐户。
生成 ssh 密钥时,建议的位置是 /home/username/.ssh... 我不确定这个建议的路径来自哪里。我已经用 git bash/ssh 键设置了几台计算机,这个建议的路径各不相同。 如何设置此建议路径?和如何设置 ssh 密钥搜索路径?
ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/plane/.ssh/id_rsa): /c/Users/username/.ssh/id_rsa
~ pwd = c/Users/username
/确实存在,但home不存在
$ ls -l /
total 3076
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 bin/
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 cmd/
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 dev/
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 etc/
-rwxr-xr-x 1 username 1061577 152112 Jan 13 20:31 git-bash.exe*
-rwxr-xr-x 1 username 1061577 151600 Jan 13 20:31 git-cmd.exe*
-rw-r--r-- 1 username 1061577 18765 Dec 10 18:25 LICENSE.txt
drwxr-xr-x 1 username 1061577 0 Feb 3 15:56 mingw64/
dr-xr-xr-x 13 username 1061577 0 Feb 3 17:57 proc/
-rw-r--r-- 1 username 1061577 160771 Jan 13 21:08 ReleaseNotes.html
drwxr-xr-x 1 username 1061577 0 Feb 3 17:02 tmp/
-rw-r--r-- 1 username 1061577 1161914 Feb 3 15:57 unins000.dat
-rwxr-xr-x 1 username 1061577 1299888 Feb 3 15:51 unins000.exe*
-rw-r--r-- 1 username 1061577 22795 Feb 3 15:57 unins000.msg
drwxr-xr-x 1 username 1061577 0 Feb 3 15:57 usr/
权限被拒绝
mkdir -p /home/username
mkdir: cannot create directory ‘/home’: Permission denied
Git 克隆:
$ git clone ssh://git@git.example.com/project.git
Cloning into 'project'...
Could not create directory '/home/username/.ssh'.
The authenticity of host 'example' can't be established.
RSA key fingerprint is SHA256.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/home/username/.ssh/known_hosts).
example: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
编辑:
我也尝试过以下方法。
为了指出 .ssh 的实际位置以及我想要的位置。 /c/Users/plane/.ssh
git config --global core.sshCommand "ssh -i ~/.ssh/id_rsa.pub"
1) 无法创建 '/home/plane/.ssh'
2) 未能将主机添加到已知主机列表(/home/plane/.ssh/known_hosts)。
3) 加载密钥“/c/Users/plane/.ssh/id_rsa.pub”:格式无效
git clone ssh://git@git.project
Cloning into 'project'...
Could not create directory '/home/plane/.ssh'.
The authenticity of host can't be established.
RSA key fingerprint is SHA256:.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Failed to add the host to the list of known hosts (/home/plane/.ssh/known_hosts).
Load key "/c/Users/plane/.ssh/id_rsa.pub": invalid format
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
谢谢,
【问题讨论】:
-
这真的很旧/晚了,但你应该使用私钥进行身份验证(将 pub 密钥添加到你的 Github 用户设置中)。
标签: bitbucket virtual-machine git-bash ssh-keygen