VsCode remote-ssh not working on new computer - visual-studio-code

So I've got myself a new computer. Lucky me. Win 10 Pro.
But SSH is not my strong suit. I can login to my remote server via the command line using:
ssh username#myserver.com
Promted for password - straight in.
I've moved my .pub files and the config file from the .ssh directory of my old computer to to my new computer But VScode will not login. I've used ssh-keygen to create a new key and added it to .ssh/authorized_keys on the server. No login. I just keep getting:
Load key "C:/Users/myuser/.ssh/key.pub": Permission denied
What am I missing here? I've been through the process enough times to make sure there are no spelling mistakes. Everything still works on my old computer.
EDIT:
To set up the ssh key I:
ssh-keygen -t rsa -b 4096 -f %USERPROFILE%/.ssh/pub_rsa
Then:
scp -p 22 %USERPROFILE%/.ssh/pub_rsa.pub username#server.com:~/
And finally:
cat ~/pub_rsa.pub >> ~/.ssh/authorized_keys
... and of course chmod that file to 600.
ssh -i %USERPROFILE%/.ssh/pub_rsa -p 22 username#server.com
... logs in fine without being prompted for a password.
My remote-ssh config file looks like:
Host my_remote
HostName server.com
User username
Port 22
IdentityFile C:/Users/MyDir/.ssh/pub_rsa.pub
EDIT2:
If I remove the .pub from the last line of the IdentityFile, I get this error message and VScode just repeats itself failing to log on -->

Rolled back remote-ssh to version 0.49 - and that seems to have done the trick. Check this post for similar problem/solution.

First, I confirm a ssh config file would always reference the private key (in your case pub_rsa), not the public key.
Second, regarding the flock error message, check microsoft/vscode-remote-release issue 1896
find settings: Remote.SSH: Lockfiles In Tmp
check it
(seen also in issue 2059, make sure to use the latest VSCode release)

Related

I've already setup the ssh key, but VSCode keeps asking for password

I'm using a macbook(MacOS) to connect to a remote Ubuntu server.
I copied the public ssh key to the server using ssh-copy-id and checked that the ssh key works on the terminal. When I do ssh username#x.x.x.x, connection is made without asking for password).
However, when I try to connect to the server through Visual Studio Code, VSCode keeps asking for password. Is there a way to fix this?
Thanks in advance!
It was a problem with the config file.
The VSCode needs the "absolute" path.
In case of MacOS, ssh-copy-id seems to only copy the absolute path relative to the user.
In other words, it omits "/Users/username" before "/.ssh".
Adding "/Users/username" in the IdentityFile attribute in .ssh/config solved the problem.
Check if this microsoft/vscode-remote-release issue 2518 applies:
You should be able to get out of this state by deleting the file (on the remote server side, as sudo root) in the log, /home/#####/.vscode-server/bin/78a4c91400152c0f27ba4d363eb56d2835f9903a/vscode-remote-lock.#####.78a4c91400152c0f27ba4d363eb56d2835f9903a (with unlink) or running the command "Kill VS Code Server on Host..."
If it happens again, you might try setting remote.SSH.useFlock.
The exact command to run in the command palette (View->Command Palette) is:
Remote-SSH: Kill VS Code Server on Host...
Also:
In my case, deleting entire ~/.vscode-server directory after connecting to the container through ssh using terminal worked.
(Deleting only ~/.vscode-server/bin did not work.)
The OP sukrama confirms in the comments having solved the issue
It was a problem with ssh key path in config file.
Here's a quick and handy fix: You do not have to delete the entire .vscode-server folder each time! The problem seems to be a file named 'vscode-remote-lock...'. It can be located inside a folder in ~/.vscode-server/bin/ . That file gets created at each ssh login through vscode. Run the following script on the remote host. It deletes that file whenever it is created:
while true
do
if ls /home/<your-username>/.vscode-server/bin/*/vscode-remote-lock.<your-username>.* 1> /dev/null 2>&1; then
find /home/<your-username>/.vscode-server/bin/*/ -name vscode-remote-lock.<your-username>.* -delete
echo "Killed the troublemaker! ^_^"
fi
done
The file names and the folder names may differ from machine to machine. So find the names on your machine and paste them in the script. Then run the script and you're good to go.
VSCode in my Windows machine was asking for password even with my key correctly configured (it works from the terminal).
My problem was that VSCode was choosing a wrong user. I was using a host configured in my ssh config file, and VSCode was setting the user as DOMAIN\user instead of user. I solved it configuring the correct user in my .ssh/config file:
Host dados
HostName vrt1234
User xxxxx
In case you're having this problem in Windows, keep in mind that the public/private keys that you might use to connect to a remote machine from WSL aren't the same ones that VS Code will use to connect from Windows. You need to create a separate public/private key pair for Windows, and export that private key to the remote server too.
From VS Code remote debug tips and tricks:
In a Powershell window, create a public/private key pair just as you would in a Linux terminal:
ssh-keygen -t rsa -b 4096
Then export it to the remote server:
export USER_AT_HOST="your-user-name-on-host#hostname"
export PUBKEYPATH="$HOME/.ssh/id_rsa.pub"
ssh $USER_AT_HOST "powershell New-Item -Force -ItemType Directory -Path \"\$HOME\\.ssh\"; Add-Content -Force -Path \"\$HOME\\.ssh\\authorized_keys\" -Value '$(tr -d '\n\r' < "$PUBKEYPATH")'"
Make sure you can connect via passwordless SSH via PowerShell.
Finally, in VS Code. press Ctrl+Shift+P to open the command palette and select "Remote-SSH: Open SSH Configuration File..." and edit the config file like so:
Host [convenient name]
HostName [hostname]
User [username]
IdentityFile C:\Users\[username]\.ssh\id_rsa*
Then when you run "Remote-SSH: Connect to Host..." in VS Code and choose the host above, it should connect without prompting for a password.
I had to use UseKeychain yes in my ~/.ssh/config file.
The config file looks like this:
Host server.tld
HostName server.tld
User user
UseKeychain yes
IdentityFile ~/.ssh/key
You have to enter ssh-add -K ~/.ssh/key to add your passphrase to KeyChain first.
Not enough rep to comment, but if you followed the steps from this Stack Overflow post and are still running into issues, your VSCode Remote-SSH config file path may not be set.
Make sure that the setting remote.SSH.configFile is set to ~/.ssh/config.
You could also type Ctrl + Shift + P to open the Command Palette.
Inside the Command Palette type,
Remote-SSH: Kill VS Code Server on Host...
You will be required to type in your server password for it to work.
In case this helps someone, i had a similar issue where VSC was asking for a password (instead of a passphrase).
I noticed that my key was on a network drive and it looks like VSC cannot read it there.
I moved it to a local file (C:) and it worked.
For me it was that my public auth ssh was not working and my home directory permissions were the problem. I had to remove group and other write permissions to my home directory and then everything worked:
chmod go-w ~/
(macos+vscode)
Only this worked for me:
https://www.backarapper.com/add-ssh-keys-to-ssh-agent-on-startup-in-macos/
ie: adding the key by ssh-add and then writing this in the ~/.ssh/config file:
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/[your-secure-ssh-key-name]

ssh_init: Network error: Cannot assign requested address

I am trying to set up a connection and transfer files using putty on a windows 10 platform. I have verified that the default port in putty is 22. When I run the command in the command line to connect and transfer files though I get the above error. Any idea why this is or what I should do?
Did you try:
pscp -P 22 c:\documents\foo.txt user#example.com:/tmp/foo
I had to go into the Putty Default Settings and "Save" them again, despite port 22 showing as the default. Worked for me to avoid adding the -P 22 option every time.
I had the same error and ended up at this page. The -P 22 did not solve my problem.
I use Putty saved sessions and double checked my command line and had the same error as the OP.
I was using:
pscp -l SESSION_NAME_IN_PUTTY ip:/remote_path local_path
I reviewed the command line options for pscp and changed the -l to -load and it worked.
The final command looked like:
pscp -load SESSION_NAME_IN_PUTTY ip:/remote_path local_path
Note: If you still have the error, please review your spelling of SESSION_NAME_IN_PUTTY and ensure it is an exact match. One letter off, can cause the same error.
In my case I had created a shortened "session name" in Putty -- that is, a shorter representation of the full hostname. This worked for most Putty functions -- but when I tried to use pscp I found that I needed to have a session name that was identical to the hostname.
I'm my case I was hitting this error because SSH was not enabled in Raspbian.

vscode with ubuntu + wsl 2 never prompts for gpg passphrase even after configuration just "failed to write commit data"

I'm trying to get vscode to prompt for passphrase when trying to commit as it does in windows OR at least make the time between having to enter the passphrase a lot longer.
I'm using latest on ubuntu + WSL 2, both installed today.
GPG works in the CLI if I run a test as follows:
echo "test" | gpg --clearsign
I'm being prompted for a passphrase and all is well. Then I'd be able to sign commits in vscode temporarily.
Is there an option to make the time between entering the passphrase a lot longer at least as a workaround?
EDIT:
I also have to enter this everytime I reboot my computer:
export GPG_TTY=$(tty)
Otherwise the above workaround won't work. It's been insane trying to fix this, probably spent at least 1 full day but to no use.
In your ~/.gnupg/gpg-agent.conf file, add the following:
default-cache-ttl 28800
max-cache-ttl 28800
You can also add the following to your ~/.bashrc so you do not have to manually enter it each time:
export GPG_TTY=$TTY
echo "test" | gpg --clearsign > /dev/null 2>&1
This prompts me for my password once on start and should cache for 8 hours. The > /dev/null 2>&1 bit hides the output. Currently, this is the workaround I am using--which is not ideal but bearable.

'ssh' is not recognized as an internal or external command

I have been trying to deploy my app into the Fortrabbit servers using the command line. I'm using windows. Here is what I tried :
C:\projects\riwaya>git remote add fort git#git2.eu1.frbit.com:riwaya.git
C:\projects\riwaya>git remote fort
C:\projects\riwaya>ssh u-riwaya#ssh2.eu1.frbit.com
'ssh' is not recognized as an internal or external command, operable program or batch file.
I have watched This Laracast Video and did the same as Jeffrey but it doesn't work ...
Can somebody help ?
Actually you have 2 problems here: First is that you don't have ssh installed, second is that you don't know how to deploy
Install SSH
It seems that ssh is not installed on your computer.
You can install openssh from here : http://openssh.en.softonic.com/download
Generate your key
Than you will have to geneate your ssh-key. There's a good tutorial about this here:
https://help.github.com/articles/generating-ssh-keys#platform-windows
Deploy
To deploy, you just have to push your code over git. Something like this:
git push fort master
If you get permission denied, be sure that you have put your public_key in the dashboard in the git tab.
SSH
The ssh command gives you access to your remote node. You should have received a password by email and now that you have ssh installed, you should be asked for a password when trying to connect. just input that password. If you want to use your private ssh key to connect to your server rather then typing that password, you can follow this : http://fortrabbit.com/docs/how-to/ssh-sftp/enable-public-key-authentication
For Windows, first install the git base from here: https://git-scm.com/downloads
Next, set the environment variable:
Press Windows+R and type sysdm.cpl
Select advance -> Environment variable
Select path-> edit the path and paste the below line:
C:\Program Files\Git\git-bash.exe
To test it, open the command window: press Windows+R, type cmd and then type ssh.
First of all Go to browser and install openssh here: https://github.com/PowerShell/Win32-OpenSSH/releases
Next step, extract rar file into folder and then copy and paste it in your drive.
after that run command: ssh it should work.
Next step is right click on shh in openssh folder and go to properties. Copy the path
and paste it in system variables in edit environment variables.
It will work fine.
TLDR, add this to settings.json
"terminal.integrated.env.windows":
{
"PATH": "C:/Windows/System32/OpenSSH",
},
Just found a case when the integrated terminal hasn't recognized 'ssh' as command, but you tried 'ssh' that was working on external terminals like CMD, git-bash.
That means you didn't add PATH variable to your integrated terminal.
If anyone looking for solution even now, here is how I did it for my Windows 10 machine.
Start > type 'Manage Optional Features'
Add Feature [+]
Look for OpenSSH client & select & install
After successful installation, open (close if already opened) powershell or command prompt and run ssh!

heroku Could not generate key in Windows XP

I am trying to program my first facebook app using heroku, but I can't get started. I am following the instructions heroku provides (https://devcenter.heroku.com/articles/facebook), but I cannot generate the SSH public key. Here is what I'm seeing/doing:
heroku login
(enter credentials)
Could not find an existing public key.
Would you like to generate one? (press enter)
Generating new SSH public key.
! Could not generate key:
Bryan T Anderson#BRYAN ~
I have looked on several other forums and tried the following:
tried the above commands in cmd.exe and in Git Bash
created a .ssh directory (~/.ssh)
tried "ssh-keygen -t rsa" AND "ssh-keygen -t rsa -C myemail#hotmail.com
One other strange thing I noticed is that when I "cd ~", and type pwd, it says I am in /c/Program Files/Java. Not sure why it isn't /c/Program Files/Git.
change directory to
C:\Program Files\Git\bin
and then run the command