【问题标题】:Does anybody know how to get github ssh to work CORRECTLY on WSL (Windows Subsystem for Linux) in December of 2019有谁知道如何让 github ssh 在 2019 年 12 月在 WSL(Linux 的 Windows 子系统)上正确工作
【发布时间】:2019-12-20 16:17:10
【问题描述】:

我需要运行 Windows 来进行视频编辑,但我也进行了一些编码。 Linex 是一个野兽,我希望能够在我的 Windows 计算机上使用 WSL,并能够从 WSL 执行 ssh。我正在尝试启动一个线程,人们可以在其中访问并按照 Windows 上的 WSL 和 Github ssh 的步骤进行操作。有人可以帮我找出我做错了什么,以便其他人也可以使用 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

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

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

  2. 按这些步骤共享凭据

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"
  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.

Git push 在 windows 端工作

【问题讨论】:

  • 您在 git bash 中使用的 ssh priv 密钥在 wsl 中不可用。在~/.ssh/id_rsa 中复制它,它应该可以工作
  • 并使用ssh -T git@github.com验证ssh
  • 如何将其复制到 ~/.ssh/id_rsa?

标签: git github windows-subsystem-for-linux


【解决方案1】:

我明白了!

完成上述所有步骤后,进入您的 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 文件夹。

然后打开power 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.

【讨论】:

  • 我将我的wsl主目录更改为/mnt/c/Users中的用户文件夹,运行sudo命令时我得到的只是git@github.com: Permission denied (publickey)
【解决方案2】:

步骤是这样的,

  1. 让 SSH 在您的 Windows 机器上运行。为此,请关注official guide
  2. 将 SSH 文件从 Windows 复制到 WSL。

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

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

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

cp -r /mnt/c/Users/<username>/.ssh/<file-name> ~/.ssh
  1. 修复权限

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

chmod 600 ~/.ssh/<file-name>
  1. 最后运行如下

最后一步应该是下面的命令,

ssh -T git@github.com

你现在应该可以走了。

【讨论】:

    【解决方案3】:

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

    cp -r /mnt/c/Users/&lt;username&gt;/.ssh ~/.ssh

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

    在 Windows 资源管理器打开的情况下,我将第二个 .ssh 目录中的子文件夹文件移动到 /home/&lt;username&gt;/.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:~$
    

    【讨论】:

      猜你喜欢
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      • 2022-06-13
      • 2019-07-03
      • 2021-05-05
      • 1970-01-01
      • 2020-09-01
      相关资源
      最近更新 更多