kamal: Error: Authentication failed for user
It seems like the underlying SSH client is not properly sourcing ~/.ssh/config.
I installed the key on the host:
$ ssh-copy-id -i ~/.ssh/id_rsa-work -f root@100.122.104.126
/home/ubuntu/.nix-profile/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ubuntu/.ssh/id_rsa-work.pub"
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@100.122.104.126'"
and check to make sure that only the key(s) you wanted were added.
Added a new entry to ~/.ssh/config:
...
Host 100.122.104.126
User root
IdentityFile ~/.ssh/id_rsa-work
...
Confirmed access in the shell:
$ ssh 'root@100.122.104.126' -- date
Thu Apr 13 07:55:48 UTC 2023
Hoever, when I run mrsk, it outputs the following error message:
$ mrsk audit
INFO [aeb45e8c] Running /usr/bin/env tail -n 50 mrsk-cnxt-audit.log on 100.122.104.126
ERROR (Net::SSH::AuthenticationFailed): Authentication failed for user root@100.122.104.126
Could it be trying to use a differnt key? Let’s find out.
I tried running ssh-copy-id again, without specifying the identity file to copy, and it tried to install a different entry:
$ ssh-copy-id -f root@100.122.104.126
/home/ubuntu/.nix-profile/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ubuntu/.ssh/id_somethingelse.pub"
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@100.122.104.126'"
and check to make sure that only the key(s) you wanted were added.
Unfortunately even with this key installed, mrsk was still unable to connect to the host.
Last thing I tried was removing that host entry from the ~/.ssh/config, and that’s when things finally started to work.
What’s going on? Anybody bumped into this? It seems like the underlying SSH client is indeed capable of sourcing ~/.ssh/config; however, it’s failing to use the configured identity key.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15
Commits related to this issue
- Use a custom key file in the integration tests This is not for merging, but to test whether the IdentityFile is read automatically from ~/.ssh/config. See https://github.com/mrsked/mrsk/issues/218 — committed to basecamp/kamal by djmb 3 years ago
- Use a custom key file in the integration tests This is not for merging, but to test whether the IdentityFile is read from ~/.ssh/config. See https://github.com/mrsked/mrsk/issues/218 — committed to basecamp/kamal by djmb 3 years ago
- Use a custom key file in the integration tests This is not for merging, but to test whether the IdentityFile is read from ~/.ssh/config. See https://github.com/mrsked/mrsk/issues/218 — committed to basecamp/kamal by djmb 3 years ago
- Add Docker Mount of SSH hidden directory to docker installation for MacOS As per this issue here: https://github.com/basecamp/kamal/issues/218 This exposes the hidden `.ssh` directory to the docke... — committed to savtrip/kamal-site by savtrip 2 years ago
if you use kamal with alias, u execute a container and you don’t have your .ssh. Add -v <home_path>/.ssh:/root/.ssh at alias like:
alias kamal='docker run -it --rm -v "${PWD}:/workdir" -v "/run/host-services/ssh-auth.sock:/run/host-services/ssh-au th.sock" -e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" -v <home_path>/.ssh:/root/.ssh -v /var/run/docker.sock:/var/run/docker.sock ghcr.io/basecamp/kamal:latest'I’m experiencing the same problem. I’ve installed the correct key into my ssh-agent. I’m able to login normally myself but mrsk fails to do so.
I took a look at the server I was logging into and noticed it was failing multiple times on that attempt. For my case, it was trying several other keys first before getting to the valid key on my system.
This got me back up and running.
@stewones @gioggi you guys are absolute legends, thanks for your help. I was banging my head against the computer for an hour until you reminded I was running Kamal in a docker container.
I raised a pull request in the documentation with @stewones solution: https://github.com/basecamp/kamal-site/pull/133
For whatever it’s worth, what helped me was just removing keys from ssh-agent by using
ssh-add -Dand then adding keys I actually care about withssh-add path_to_key. I had too many keys added locally to ssh agent and ssh was trying too many keys before coming to exhaustion.here’s a little improved version of @gioggi 's solution, which interpolates the current home dir. it really works.
someone could put a PR updating the docs 👀
My issue was that I have a lot of keys added to the agent and they exhausted the
MaxAuthTriesconfigured insshdon the server before it could try the correct key. For me the workaround was to addIdentitiesOnly yesalongIdentityFilein the local SSH config.The drawback is that this way it doesn’t use the SSH agent and always asks for the key’s password.
@iamFIREcracker - net-ssh reads the IdentityFile setting and https://github.com/mrsked/mrsk/pull/384 shows that working in the integration tests.
I’ve raised https://github.com/mrsked/mrsk/pull/386 which will allow the log level to be set in net-ssh. Could you try that branch, set the log level to debug and see if there’s anything useful in the output?
@freddyheppell, @luvs, @veeti-k - were you having the exact same issue with the IdentityFile setting as @iamFIREcracker? In any case could you also that branch to get some debug information?
Checkout this post, it was what solved it for me!
https://stackoverflow.com/questions/41369406/netsshauthenticationfailed-authentication-failed-for-user