有谁知道如何让 github ssh 在 2019 年 12 月在 WSL(Linux 的 Windows 子系统)上正确工作

And*_* II 8 git github windows-subsystem-for-linux

我需要运行 Windows 进行视频编辑,但我也做一些编码。Linex 是一头野兽,我希望能够在我的 Windows 计算机上使用 WSL,并且能够从 WSL 执行 ssh。我正在尝试启动一个线程,人们可以在该线程中按照 WSL 和 Github ssh 在 Windows 上的步骤操作。有人可以帮我弄清楚我做错了什么,以便其他人也可以使用 WSL 和 Github 吗?

我的步骤:

  1. 重置窗口
  2. 转到此站点并安装 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
  3. 设置和升级 Ubuntu:
    sudo apt update && sudo apt upgrade
  4. 使用此网站安装 VS Code:https : //code.visualstudio.com/docs/remote/wsl
  5. 安装远程开发包:https ://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack
  6. 使用默认值在 Windows 上设置 gitbash
  7. 使用此站点设置 git ssh:https : //help.github.com/en/github/authenticating-to-github/checking-for-existing-ssh-keys
  8. git clone 是否进行了更改并推送到 master 以确保一切正常,确实如此。
  9. 添加了一个 .gitattributes 文件到 repo
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
Run Code Online (Sandbox Code Playgroud)

(有没有办法让它自动?)

  1. 然后我运行了这个命令,因为它在网站上建议了它......
git config --global core.autocrlf input
Run Code Online (Sandbox Code Playgroud)
  1. Git 仍然有效

  2. dis 这些步骤来共享凭据

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"
Run Code Online (Sandbox Code Playgroud)
  1. 从 wsl 运行 git push 并得到错误:
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.
Run Code Online (Sandbox Code Playgroud)

Git 推送适用于 Windows 端

And*_* II 15

尤里卡我明白了!!

完成上述所有步骤后,进入 Windows 终端并运行:

$ ssh -T git@github.com
Run Code Online (Sandbox Code Playgroud)

你应该得到:

You've successfully authenticated, but GitHub does not provide shell access.
Run Code Online (Sandbox Code Playgroud)

然后在ubuntu上输入:

$ cd
$ cd .ssh 
$ code .
Run Code Online (Sandbox Code Playgroud)

这将在 VS Code 中打开 ubuntu .ssh 文件夹。

然后打开电源外壳并运行:

> cd .ssh
> code .
Run Code Online (Sandbox Code Playgroud)

这将在 VS Code 中打开 Windows .ssh 文件夹。

然后你可以通过 VS Code 将 Windows 文件拖放到 ubuntu。

现在返回 WSL 终端并运行:

$ ssh -T git@github.com
Run Code Online (Sandbox Code Playgroud)

如果你得到:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         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).
Run Code Online (Sandbox Code Playgroud)

然后运行:

$ sudo chmod 600 ~/.ssh/id_rsa
$ sudo chmod 600 ~/.ssh/id_rsa.pub
Run Code Online (Sandbox Code Playgroud)

现在当你运行时:

$ ssh -T git@github.com
Run Code Online (Sandbox Code Playgroud)

你应该得到:

You've successfully authenticated, but GitHub does not provide shell access.
Run Code Online (Sandbox Code Playgroud)

  • 我将我的 wsl 主目录更改为“/mnt/c/Users”中的用户文件夹,当运行 sudo 命令时,我得到的只是“git@github.com:权限被拒绝(公钥)” (3认同)

gpr*_*our 8

步骤如下:

  1. 让 SSH 在您的 Windows 计算机上运行。为此,请遵循官方指南
  2. 将 SSH 文件从 Windows 复制到 WSL。

为此,您可以尝试使用以下命令,

cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
Run Code Online (Sandbox Code Playgroud)

如果目录复制不起作用,那么您也可以尝试复制单个文件。

cp -r /mnt/c/Users/<username>/.ssh/<file-name> ~/.ssh
Run Code Online (Sandbox Code Playgroud)
  1. 修复权限

如果出现权限错误,请将显示错误的文件的权限更改为 600。

chmod 600 ~/.ssh/<file-name>
Run Code Online (Sandbox Code Playgroud)
  1. 最后运行以下命令

最后一步应该是以下命令,

ssh -T git@github.com
Run Code Online (Sandbox Code Playgroud)

你现在应该可以走了。


smo*_*re4 5

在尝试了许多其他解决方案之后,这对我有用。具体来说,我想我可以使用以下命令从本地 Windows 文件夹复制到 Ubuntu:

cp -r /mnt/c/Users/<username>/.ssh ~/.ssh

但这对我不起作用。只有当我打开 WSL 文件结构时,explorer.exe .我才看到有两个 .ssh 目录。

打开 Windows 资源管理器后,我将第二个 .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:~$
Run Code Online (Sandbox Code Playgroud)