Reputation: 838
I need to run windows for video editing but I also do some coding. Linex is a beast and I would love to be able to use WSL on my windows computer and be able to do ssh from WSL. I am trying to start a thread where people can go to and follow the steps for WSL and Github ssh on windows. Can someone help me figure out what I am doing wrong so others can use WSL and Github as well?
My steps:
sudo apt update && sudo apt upgrade
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
(is there a way to make this automatic?)
git config --global core.autocrlf input
Git still works
dis these steps to share credentials
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"
[email protected]: 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 works on windows side
Upvotes: 29
Views: 47257
Reputation: 5355
Just adding to the other excellent answers here.
First turning on verbose mode (ssh -vT
) was very helpful. It allows you to see the paths that ssh is trying when it looks for your keys.
C:\Users\Me\.ssh>ssh -vT [email protected]
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug1: Reading configuration data C:\\Users\\Me/.ssh/config
debug1: C:\\Users\\Me/.ssh/config line 1: Applying options for github.com
debug1: Connecting to github.com [140.82.121.3] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\Me\\.ssh\\id_ed25519 type 3
debug1: identity file C:\\Users\\Me\\.ssh\\id_ed25519-cert type -1
debug1: identity file /c/Users/Me/.ssh/id_ed25519 type -1
debug1: identity file /c/Users/Me/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
If those paths aren't what you expect, that gives you a direction to start digging deeper.
Another thing that caught me on Windows was that there was an old version of ssh in my path that was screwing things up. You can verify which ssh you are running with:
C:\Users\Me\.ssh>where ssh
C:\Windows\System32\OpenSSH\ssh.exe
Finally, with verbose mode I was able to see that an unexpected key was being used instead of the one I wanted. I edited the .ssh/config
file and added a section for Host github.com
and a line like this:
IdentityFile C:\Users\Me\.ssh\id_ed25519
WSL also has its own .ssh/config
file and the paths there may need to be different.
Upvotes: 1
Reputation: 4866
After trying numerous other solutions, this is what worked for me. Specifically, I thought I could copy from my local Windows folder to Ubuntu with this command:
cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
But this did not work for me. It is only when I opened the WSL file structure with explorer.exe .
did I see that there were two .ssh directories.
With Windows Explorer open, I moved the subfolder files in the second .ssh directory to the /home/<username>/.ssh
directory. Then it worked.
sam@SAM-SAM:~$ explorer.exe .
sam@SAM-SAM:~$ ssh -T [email protected]
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
[email protected]: Permission denied (publickey).
sam@SAM-SAM:~$ sudo chmod 600 /home/sam/.ssh/id_rsa
[sudo] password for sam:
sam@SAM-SAM:~$ ssh -T [email protected]
Hi foouser! You've successfully authenticated, but GitHub does not provide shell access.
sam@SAM-SAM:~$
Upvotes: 6
Reputation: 15333
The steps would be like,
For this you can try with the following commands,
cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
If the directory copy doesn't work, then you can try to copy single file as well.
cp -r /mnt/c/Users/<username>/.ssh/<file-name> ~/.ssh
If it gives error for permission, then change the permission to 600 for the file for which it shows error.
chmod 600 ~/.ssh/<file-name>
Last step should be the following command,
ssh -T [email protected]
You should be good to go now.
Upvotes: 12
Reputation: 838
Eureka I got it!!
After all the steps above go into your windows terminal and run:
$ ssh -T [email protected]
You should get:
You've successfully authenticated, but GitHub does not provide shell access.
Then on ubuntu enter:
$ cd
$ cd .ssh
$ code .
This will open up your ubuntu .ssh folder in VS code.
Then open power shell and run:
> cd .ssh
> code .
This will open up your windows .ssh folder in VS code.
Then you can drag and drop your windows fils to ubuntu through vs code.
Now go back to your WSL terminal and run:
$ ssh -T [email protected]
If you get:
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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
[email protected]: Permission denied (publickey).
Then run:
$ sudo chmod 600 ~/.ssh/id_rsa
$ sudo chmod 600 ~/.ssh/id_rsa.pub
Now when you run:
$ ssh -T [email protected]
You should get:
You've successfully authenticated, but GitHub does not provide shell access.
Upvotes: 24