有谁知道如何在 2019 年 12 月让 github ssh 在 WSL(Windows 子系统 Linux)上正确工作
Does anybody know how to get github ssh to work CORRECTLY on WSL (Windows Subsystem for Linux) in December of 2019
我需要 运行 windows 进行视频编辑,但我也会做一些编码。 Linex 是一头野兽,我希望能够在我的 windows 计算机上使用 WSL 并能够从 WSL 执行 ssh。我正在尝试启动一个线程,人们可以在该线程中按照 WSL 和 windows 上的 Github ssh 的步骤进行操作。有人可以帮我弄清楚我做错了什么,以便其他人也可以使用 WSL 和 Github 吗?
我的步骤:
- 重置windows
- 转到此站点并安装 WSL https://docs.microsoft.com/en-us/windows/wsl/install-win10
我选择了 Ubuntu 18.04 LTS:https://www.microsoft.com/en-us/p/ubuntu-1804-lts/9n9tngvndl3q?rtc=1&activetab=pivot:overviewtab
- 设置和升级 Ubuntu:
sudo apt update && sudo apt upgrade
- 使用此网站安装 VS Code:https://code.visualstudio.com/docs/remote/wsl
- 已安装远程开发包:https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
- 使用默认值
在 windows 上设置 gitbash
- 设置 git 与此站点的 ssh:https://help.github.com/en/github/authenticating-to-github/checking-for-existing-ssh-keys
- git 克隆是否进行了更改并推送到 master 以确保一切正常,确实如此。
- 添加了一个 .gitattributes 文件到 repo
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
(有没有办法让它自动进行?)
- 然后我运行这个命令因为它在网站上建议...
git config --global core.autocrlf input
Git 仍然有效
执行这些步骤以共享凭据
Configure the credential manager on Windows by running the following in a Windows command prompt or PowerShell:
git config --global credential.helper wincred
Configure WSL to use the same credential helper, but running the following in a WSL terminal:
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-wincred.exe"
- 运行 git 从 wsl 推送和 goterror:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Git 推送在 windows 端工作
尤里卡我明白了!!
完成上述所有步骤后,进入您的 windows 终端并 运行:
$ ssh -T git@github.com
你应该得到:
You've successfully authenticated, but GitHub does not provide shell access.
然后在 ubuntu 输入:
$ cd
$ cd .ssh
$ code .
这将在 VS 代码中打开您的 ubuntu.ssh 文件夹。
然后打开电源shell和运行:
> cd .ssh
> code .
这将在 VS 代码中打开您的 windows.ssh 文件夹。
然后您可以通过 vs 代码将 windows 文件拖放到 ubuntu。
现在返回您的 WSL 终端并 运行:
$ ssh -T git@github.com
如果你得到:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0666 for '/home/andre/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/andre/.ssh/id_rsa": bad permissions
git@github.com: Permission denied (publickey).
然后运行:
$ sudo chmod 600 ~/.ssh/id_rsa
$ sudo chmod 600 ~/.ssh/id_rsa.pub
现在当你 运行:
$ ssh -T git@github.com
你应该得到:
You've successfully authenticated, but GitHub does not provide shell access.
步骤是这样的,
- 让 SSH 在您的 Windows 机器上运行。为此,请遵循 official guide.
- 将 SSH 文件从 Windows 复制到 WSL。
为此,您可以尝试使用以下命令,
cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
如果目录复制不行,那么您也可以尝试复制单个文件。
cp -r /mnt/c/Users/<username>/.ssh/<file-name> ~/.ssh
- 修复权限
如果它给出权限错误,则将它显示错误的文件的权限更改为 600。
chmod 600 ~/.ssh/<file-name>
- 终于运行以下
最后一步应该是以下命令,
ssh -T git@github.com
你现在应该可以走了。
在尝试了许多其他解决方案之后,这就是对我有用的方法。具体来说,我认为我可以使用以下命令从本地 Windows 文件夹复制到 Ubuntu:
cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
但这对我不起作用。只有当我用 explorer.exe .
打开 WSL 文件结构时,我才看到有两个 .ssh 目录。
打开 Windows Explorer,我将第二个 .ssh 目录中的子文件夹文件移动到 /home/<username>/.ssh
目录。然后就成功了。
sam@SAM-SAM:~$ explorer.exe .
sam@SAM-SAM:~$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '140.82.113.4' to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/sam/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/sam/.ssh/id_rsa": bad permissions
git@github.com: Permission denied (publickey).
sam@SAM-SAM:~$ sudo chmod 600 /home/sam/.ssh/id_rsa
[sudo] password for sam:
sam@SAM-SAM:~$ ssh -T git@github.com
Hi foouser! You've successfully authenticated, but GitHub does not provide shell access.
sam@SAM-SAM:~$
我需要 运行 windows 进行视频编辑,但我也会做一些编码。 Linex 是一头野兽,我希望能够在我的 windows 计算机上使用 WSL 并能够从 WSL 执行 ssh。我正在尝试启动一个线程,人们可以在该线程中按照 WSL 和 windows 上的 Github ssh 的步骤进行操作。有人可以帮我弄清楚我做错了什么,以便其他人也可以使用 WSL 和 Github 吗?
我的步骤:
- 重置windows
- 转到此站点并安装 WSL https://docs.microsoft.com/en-us/windows/wsl/install-win10 我选择了 Ubuntu 18.04 LTS:https://www.microsoft.com/en-us/p/ubuntu-1804-lts/9n9tngvndl3q?rtc=1&activetab=pivot:overviewtab
- 设置和升级 Ubuntu:
sudo apt update && sudo apt upgrade
- 使用此网站安装 VS Code:https://code.visualstudio.com/docs/remote/wsl
- 已安装远程开发包:https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
- 使用默认值 在 windows 上设置 gitbash
- 设置 git 与此站点的 ssh:https://help.github.com/en/github/authenticating-to-github/checking-for-existing-ssh-keys
- git 克隆是否进行了更改并推送到 master 以确保一切正常,确实如此。
- 添加了一个 .gitattributes 文件到 repo
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
(有没有办法让它自动进行?)
- 然后我运行这个命令因为它在网站上建议...
git config --global core.autocrlf input
Git 仍然有效
执行这些步骤以共享凭据
Configure the credential manager on Windows by running the following in a Windows command prompt or PowerShell:
git config --global credential.helper wincred
Configure WSL to use the same credential helper, but running the following in a WSL terminal:
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-wincred.exe"
- 运行 git 从 wsl 推送和 goterror:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Git 推送在 windows 端工作
尤里卡我明白了!!
完成上述所有步骤后,进入您的 windows 终端并 运行:
$ ssh -T git@github.com
你应该得到:
You've successfully authenticated, but GitHub does not provide shell access.
然后在 ubuntu 输入:
$ cd
$ cd .ssh
$ code .
这将在 VS 代码中打开您的 ubuntu.ssh 文件夹。
然后打开电源shell和运行:
> cd .ssh
> code .
这将在 VS 代码中打开您的 windows.ssh 文件夹。
然后您可以通过 vs 代码将 windows 文件拖放到 ubuntu。
现在返回您的 WSL 终端并 运行:
$ ssh -T git@github.com
如果你得到:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0666 for '/home/andre/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/andre/.ssh/id_rsa": bad permissions
git@github.com: Permission denied (publickey).
然后运行:
$ sudo chmod 600 ~/.ssh/id_rsa
$ sudo chmod 600 ~/.ssh/id_rsa.pub
现在当你 运行:
$ ssh -T git@github.com
你应该得到:
You've successfully authenticated, but GitHub does not provide shell access.
步骤是这样的,
- 让 SSH 在您的 Windows 机器上运行。为此,请遵循 official guide.
- 将 SSH 文件从 Windows 复制到 WSL。
为此,您可以尝试使用以下命令,
cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
如果目录复制不行,那么您也可以尝试复制单个文件。
cp -r /mnt/c/Users/<username>/.ssh/<file-name> ~/.ssh
- 修复权限
如果它给出权限错误,则将它显示错误的文件的权限更改为 600。
chmod 600 ~/.ssh/<file-name>
- 终于运行以下
最后一步应该是以下命令,
ssh -T git@github.com
你现在应该可以走了。
在尝试了许多其他解决方案之后,这就是对我有用的方法。具体来说,我认为我可以使用以下命令从本地 Windows 文件夹复制到 Ubuntu:
cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
但这对我不起作用。只有当我用 explorer.exe .
打开 WSL 文件结构时,我才看到有两个 .ssh 目录。
打开 Windows Explorer,我将第二个 .ssh 目录中的子文件夹文件移动到 /home/<username>/.ssh
目录。然后就成功了。
sam@SAM-SAM:~$ explorer.exe .
sam@SAM-SAM:~$ ssh -T git@github.com
Warning: Permanently added the RSA host key for IP address '140.82.113.4' to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: UNPROTECTED PRIVATE KEY FILE! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/home/sam/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/home/sam/.ssh/id_rsa": bad permissions
git@github.com: Permission denied (publickey).
sam@SAM-SAM:~$ sudo chmod 600 /home/sam/.ssh/id_rsa
[sudo] password for sam:
sam@SAM-SAM:~$ ssh -T git@github.com
Hi foouser! You've successfully authenticated, but GitHub does not provide shell access.
sam@SAM-SAM:~$