Ssh fails to use private key from ssh-agent: communication with agent failed - linux

I'm getting an error when using ssh, which tries to use keys from ssh-agent, but fails with this message (when running ssh -v):
debug1: get_agent_identities: ssh_fetch_identitylist: communication with agent failed
Full log
I can see both of my keys added to the agent when running ssh-add -l:
$ ssh-add -l
3072 SHA256:0i3sqR60WRsAOpFVJyw951NUDW01jkAWFB1na921Asd xxxxxx#somehost (RSA)
4096 SHA256:CG6njka821AOd82j1xGFkyiOjwG/yo921KAIOWm3t/4 xxxxxx#anotherhost (RSA)
The same error appears with no keys or one key inside the agent.
I'm running the fish shell on Archlinux, and also tried this under bash, but it doesn't seem to make a difference. The same setup was working for me on Ubuntu. There seem to be no questions about this exact issue, and I'm stuck with no clues.

I found that this problem on my pc is caused by the windows default ssh client which stores my ssh key files. After upgrading to 8.9 with https://github.com/PowerShell/Win32-OpenSSH/releases/tag/v8.9.0.0p1-Beta I solved this problem.

Related

Trouble with GitHub and ssh keys?

From one of my hosts I can authenticate with ssh to GitHub, from another I cannot git#github.com: Permission denied (publickey).
I was having some issues from my Mac creating a new repo and pushing to it, I always got a permission denied error. However from my Linux host it worked fine.
I checked the repos for deploy keys (in case this was causing the issue), none of my repos had a deploy key set.
I checked the keys on GitHub and there was only one ssh key installed. I deleted this key and tested, as expected the repos from the Linux host could not connect, yet the Mac could still connect.
From the Mac:
ssh -T git#github.com Hi mcdent/blog1! You've successfully authenticated, but GitHub does not provide shell access. bash-3.2$
From Linux:
[mike#docker1 doing]$ ssh -T git#github.com git#github.com: Permission denied (publickey). [mike#docker1 doing]$
I'm puzzled as to how the Mac is still authenticating? I likely did have a repo called blog1 in the past but I certainly don't now.
Ideally I'd like to have a single key used on GitHub, which I can use with both my Linux and MacOS hosts.
Any pointers very welcome.
I'm puzzled as to how the Mac is still authenticating?
Then try a ssh -Tv git#github.com.
You will see which key file is accessed and used for this authentication.
It should be a private key whose public key is registered to your account.
Check your environment variables or git config --global / git config --system -l for anything including blog1.

VS Code SSH Remote Connection issues

I have been using VS Code and connecting remotely from home on my MacBookPro to work on a college project for the past month and for some reason it will not connect to the Computer Lab Server anymore. No idea why this is happening but it just stopped working today. I tried re-installing vs code and also installed it on my wife's computer but it still wont connect through remote ssh. No idea why this is happening but now I have no way to debug my code and have to just edit everything using emacs through the terminal app on my mac. I didn't make any changes from last night to this morning.. I can still ssh into the Computer Lab server from terminal fine. Bellow is some of the log that seems to repeat itself while it is trying to connect using the extension: remote ssh.
Any help on this would be greatly appreciated, or are there other IDE's that are somewhat easy to connect remotely through ssh available for Mac?
MY LOG:
17:09:21.150] Log Level: 2
[17:09:21.152] remote-ssh#0.55.0
[17:09:21.152] darwin x64
[17:09:21.153] SSH Resolver called for "ssh- remote+7b22686f73744e616d65223a226c696e75782e63732e75736d2e6d61696e652e656475222c2275736572223a22746b7766c6b227d", attempt 1
[17:09:21.154] SSH Resolver called for host: tkwilk#linux.cs.usm.maine.edu
[17:09:21.154] Setting up SSH remote "linux.cs.usm.maine.edu"
[17:09:21.158] Acquiring local install lock: /var/folders/9y/scfwvr0577qfgs_l_c5ym13m0000gq/T/vscode-remote-ssh-tkwilk#linux.cs.usm.maine.edu-install.lock
[17:09:21.192] Looking for existing server data file at /Users/twilk31888 1/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-tkwilk#linux.cs.usm.maine.edu-93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3-0.55.0/data.json
[17:09:21.194] Using commit id "93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3" and quality "stable" for server
[17:09:21.195] Install and start server if needed
[17:09:21.220] Checking ssh with "ssh -V"
[17:09:21.233] > OpenSSH_8.1p1, LibreSSL 2.7.3
[17:09:21.249] askpass server listening on /var/folders/9y/scfwvr0577qfgs_l_c5ym13m0000gq/T/vscode-ssh-askpass-a45a56dcf061823c964fa6ae7ff720ac39d2477f.sock
[17:09:21.249] Spawning local server with {"ipcHandlePath":"/var/folders/9y/scfwvr0577qfgs_l_c5ym13m0000gq/T/vscode-ssh-askpass-c1cf58194111018972f9cf0cd413a94b7293bda9.sock","sshCommand":"ssh","sshArgs":["-v","-T","-D","54601","-o","ConnectTimeout=15","tkwilk#linux.cs.usm.maine.edu"],"dataFilePath":"/Users/twilk31888 1/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-tkwilk#linux.cs.usm.maine.edu-93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3-0.55.0/data.json"}
[17:09:21.249] Local server env: {"DISPLAY":"1","ELECTRON_RUN_AS_NODE":"1","SSH_ASKPASS":"/Users/twilk31888 1/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/local-server/askpass.sh","VSCODE_SSH_ASKPASS_NODE":"/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer)","VSCODE_SSH_ASKPASS_MAIN":"/Users/twilk31888 1/.vscode/extensions/ms-vscode-remote.remote-ssh-0.55.0/out/askpass-main.js","VSCODE_SSH_ASKPASS_HANDLE":"/var/folders/9y/scfwvr0577qfgs_l_c5ym13m0000gq/T/vscode-ssh-askpass-a45a56dcf061823c964fa6ae7ff720ac39d2477f.sock"}
[17:09:21.262] Spawned 4239
[17:09:21.373] > local-server> Spawned ssh: 4240
[17:09:21.379] stderr> OpenSSH_8.1p1, LibreSSL 2.7.3
[17:09:21.756] stderr> debug1: Server host key: ecdsa-sha2-nistp256 SHA256:wny4SU/uVC6y9cUUH5kJnRe5SVWpBhWGABpWSYzMNG0
[17:09:22.132] stderr> Authenticated to linux.cs.usm.maine.edu ([130.111.131.121]:22).
[17:09:22.490] > ready: 946b80caa0f2
[17:09:22.553] > Linux 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020
[17:09:22.554] Platform: linux
[17:09:22.685] > 946b80caa0f2: running
[17:09:22.713] > Acquiring lock on /home/students/tkwilk/.vscode-server/bin/93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3/vscode-remote-lock.tkwilk.93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3
> Installation already in progress...
> 946b80caa0f2##24##
[17:09:22.714] Received install output: 946b80caa0f2##24##
[17:09:22.714] Server installation process already in progress - waiting and retrying
[17:09:22.714] Terminating local server
[17:09:22.740] Local server exit: 15
The key info is provided at the line
[17:09:22.713] > Acquiring lock on /home/students/tkwilk/.vscode-server/bin/93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3/vscode-remote-lock.tkwilk.93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3
If you could ssh into the server and remove the file by
rm -rf /home/students/tkwilk/.vscode-server/bin/93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3/vscode-remote-lock.tkwilk.93c2f0fbf16c5a4b10e4d5f89737d9c2c25488a3
then reboot the vscode and try to connect, things should be fine.
Encountered the same problem on two servers with two different causes:
One problem is solved by referring to this issue: #2805
Command Palette -> Select "Remote-SSH: Kill VS Code Server on Host..."
Remove the directory of "~/.vscode-server" on remote server.
The other problems, is caused by running out of storage quota on that server. And the issue was automatically solved when the quota was increased.
Most of the microsoft/vscode-remote-release I see, like issue 2901, are about a failed symlink on the target server.
If you can ssh in command line, try and rename /home/students/tkwilk/.vscode-server in order to force a complete re-installation of the SSH remote plugin by VSCode.
mv ~/.vscode-server ~/.vscode-server-old
Try and connect to that server through VSCode and see if the issue persists, when it tries to redo the complete vscode-server SSH setup.
I found a new reason, but it may be rare:
Before I found this problem, I had updated and modified the linux kernel of the remote virtual machine, and modified the UTS_SYSNAME located in /include/linux/uts.h;
#define UTS_SYSNAME "Linux Clstilmldy-LZM"
// #define UTS_SYSNAME "Linux"
So I met this problem, but I never found a feasible solution;
I carefully looked at the vscode output and found that vscode remote ssh: Unsupported platform: Linux Clstilmldy LZM;
[16:38:25.333] SSH Resolver called for host: Ubuntu
[16:38:25.334] Setting up SSH remote "Ubuntu"
...
[16:38:35.555] Got password response
[16:38:35.555] "install" wrote data to terminal: "******"
[16:38:35.574] >
[16:38:36.069] > ac25402ecd5f: running
[16:38:36.086] > Unsupported platform: Linux Clstilmldy-LZM
[16:38:36.096] > ac25402ecd5f: start
I guess that vscode remote ssh does not recognize system names other than Linux, Mac, and Windows, so I changed this line back.
I recompile and install the kernel.
okkk, I solve the problem.
Another answer, since none of these worked for me. Try toggling off the following setting in VSCode: remote.SSH.useFlock

SSL handshake failed when trying to add remote GitLab account in GitAhead under openSUSE Leap 15

I successfully added remote (private) GitLab account under Windows 10 in GitAhead but under a Linux openSUSE Leap 15 I got "Connection failed: SSL handshake failed".
Note that I can clone, pull, fetch, commit, push in repositories from repositories in the GitLab I want to add, I also tried to reset SSH handshake with:
$ ssh-keygen -R gitlab.mydomain.net
# Host gitlab.mydomain.net found: line 31
/home/user/.ssh/known_hosts updated.
Original contents retained as /home/user/.ssh/known_hosts.old
$ ssh git#gitlab.mydomain.net
The authenticity of host 'gitlab.mydomain.net (<IP>)' can't be established.
ECDSA key fingerprint is SHA256:**************.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.mydomain.net,<IP>' (ECDSA) to the list of known hosts.
Welcome to GitLab, #UserName!
Connection to gitlab.mydomain.net closed.
But it still does not work, anyone knows if there is something to configure to allow it under Linux ?
Thanks
For a starter, check the rights on directories on the server-side. The home-dir as well as the .ssh-dir should be treated with chmod 700. The same is true for the key files.
You should aim for a passwordless login on your server. As soon as this works, GitAhead should be fine. If you have a Git-Shell in your server-side /etc/passwd, replace it by /bin/sh for the sake of sending your pubkey: On the client, enter ssh-copy-id -i yourprivatekeyfile somerandomgituser#ipofyourgitserver. After that, if successful, you can reset the /etc/passwd line back to the Git-Shell.

Missing files in .ssh directory

I have updated my system with sudo apt-get update.
There was a update of PAM (The Pluggable Authentication Module). I don't remember the message, but there was like a pink screen and I decided to choose no (sorry for that poor explanation).
After that the update continues until something like ssh stop/waiting and then nothing happens. I couldn't cancel this und decided to reboot my Ubuntu Server (14.04 LTS).
After that I cannot connect with a user to this machine with ssh -X user#host. Only the owner can connect. But no other user.
With ssh -v user#host I get the error
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
Then I recognized that there are a lot of missing files in my ~/.ssh/ directory.
There is only the file known_hosts. I think there should be also the files: Readme, authorized_keys, bup, deprec, id_dsa, id_dsa.pub.
Do I have to reinstall ssh?
You do not need to reinstall ssh.
Many of those files are generate as you use ssh and related commands.
The most important files in my experience (which you will generate) are:
authorized_keys: contains public keys which are authorized to connect.
id_dsa and id_dsa.pub (or id_rsa, etc.) are the private key and public key (with .pub suffix) are the keys you offer when attempting a connection. These are generated by executing ssh-keygen.
Also, config is nice to use, but also not necessary. see man ssh_config.
Restoring connections from other machines
It appears you've lost the authorized_keys file you had. If you wish to continue connecting via publickey from other machines, you will need to put the public key from the other machine into your authorized_keys file.
Ensure authorized_keys file exists (if not: touch ~/.ssh/authorized_keys)
Copy the public key (id_rsa.pub for example) from the machine[s] you will be connecting from.
Paste the public key[s] into authorized_keys, one per line.

gitlab error - the remote en hung up unexpectedly

I installed Gitlab on my Ubuntu successfully(gitlab.domain.com), on a client PC I installed Git (windows 7), then run Git Bash to generate SSH keys with command: ssh-keygen -t rsa -C "username#domain.com" to create private/public keys on C:\Users\AccountName.ssh
Then, add public key to profile on installed gitlab. Then can clone/push on Git Bash.
However, I can not reproduce this on other PCs, I tried some PCs, created new users, new ssh keys...
but always encounter that error "The remote end hung up unexpectedly", sometimes can clone but also get that error when pushing.
I can only clone/push on first PC. I'm so confused, don't know what I missed. I'm trying to get my team on Git
Thanks a lot for any advice
Make sure you are pointing it at the correct git server. Also - login on your Jenkins server (Under the jenkins user) and ssh to git#your-git-server and make sure to select 'yes' to add the server to your known hosts.
I had the same error and it was an access-level problem :
my user only had guest access to my project so it wasn't able to clone it. I changed the access level to developper and it solved my problem

Resources