this post was submitted on 14 Aug 2024
108 points (99.1% liked)

Linux

47233 readers
757 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS
 

I have my own ssh server (on raspberry pi 5, Ubuntu Server 23) but when I try to connect from my PC using key authentication (having password disabled), I get a blank screen. A blinking cursor.

However, once I enter the command eval "$(ssh-agent -s)" and try ssh again, I successfully login after entering my passphrase. I don't want to issue this command every time. Is that possible?

This does not occur when I have password enabled on the ssh server. Also, ideally, I want to enter my passphrase EVERYTIME I connect to my server, so ideally I don't want it to be stored in cache or something. I want the passphrase to be a lil' password so that other people can't accidentally connect to my server when they use my PC.

top 50 comments
sorted by: hot top controversial new old
[–] INeedMana@lemmy.world 46 points 4 weeks ago (4 children)

The whole point of ssh-agent is to remember your passphrase. If you don't want to do that your problem might be that for some reason ssh client doesn't pick up your key. Try defining it for the host

Also, there's -v flag for ssh. Use it to debug what's going on when it doesn't try to use your key

[–] dysprosium@lemmy.dbzer0.com 7 points 4 weeks ago* (last edited 4 weeks ago) (1 children)

okay I tried that, using -i to specify private key. I get the same thing: blank / blinking cursor. When I use verbose -v flag, I see that in all cases (using -i, the config file, and originally) it ends with these two lines (after about 50 lines) :

debug1: Offering public key: /home/username/.ssh/id_rsa RSA SHA256:j3MUkYzhTrjC6PHkIbre3O(etc) agent
debug1: Server accepts key: /home/username/.ssh/id_rsa RSA SHA256:j3MUkYzhTrjC6PHkIbre3OT(etc) agent

where (etc) is some redacted text. It seems the server is ACCEPTING the key, which is nice. But then it's still a blinking cursor...

[–] NeoNachtwaechter@lemmy.world 2 points 4 weeks ago (1 children)

It seems the server is ACCEPTING the key

Check if it is true. In the server logs.

[–] dysprosium@lemmy.dbzer0.com 4 points 4 weeks ago* (last edited 4 weeks ago) (1 children)

I'm not sure which logs I can and should check, but when I listen to this: sudo tail -f /var/log/auth.log

I only get this right after I ctrl+C on my blank / blinking cursor screen. (Did this 3 times in a row.)

2024-08-14T11:35:32.874228+02:00 pidoos sshd[3957]: Connection closed by authenticating user pi MY_PUBLIC_IP port 52242 [preauth]
2024-08-14T11:35:50.168160+02:00 pidoos sshd[3975]: Connection closed by authenticating user pi MY_PUBLIC_IP port 39266 [preauth]
2024-08-14T11:35:55.236347+02:00 pidoos sshd[3987]: Connection closed by authenticating user pi MY_PUBLIC_IP port 41318 [preauth]

Where MY_PUBLIC_IP is redacted. I'm not even sure why my public IP is showing. I connect locally. But ports are forwarded, yes.

Using sudo journalctl -u sshd -f does not seem to output anything...

[–] gedhrel@lemmy.world 2 points 4 weeks ago

That's only part of the handshake. It'd require agent input around that point.

[–] smb@lemmy.ml 6 points 4 weeks ago

The whole point of ssh-agent is to remember your passphrase.

replace passphrase with private key and you're very correct.

passphrases used to login to servers using PasswordAuthentication are not stored in the agent. i might be wrong with technical details on how the private key is actually stored in RAM by the agent, but in the context of ssh passphrases that could be directly used for login to servers, saying the agent stores passphrases is at least a bit misleading.

what you want is:

  • use Key authentication, not passwords
  • disable passwordauthentication on the server when you have setup and secured (some sort of backup) ssh access with keys instead of passwords.
  • if you always want to provide a short password for login, then don't use an agent, i.e. unset that environment variable and check ssh_config
  • give your private key a password that fits your needs (average time it shoulf take attackers to guess that password vs your time you need overall to exchange the pubkey on all your servers)
  • change the privatekey every time immediately after someone might have had access to the password protected privkey file
  • do not give others access to your account on your pc to not have to change your private key too often.

also an idea:

  • use a token that stores the private key AND is PIN protected as in it would lock itself upon a few tries with a wrong pin. this way the "password" needed to enter for logins can be minimal while at the same time protecting the private key from beeing copied. but even then one should not let others have access to the same machine (of course not as root) or account (as user, but better not at all) as an unlocked token could also possibly be used to place a second attacker provided key on the server you wanted to protect.

all depends on the level of security you want to achieve. additional TOTP could improve security too (but beware that some authenticator providers might have "sharing" features which could compromise the TOTP token even before its first use.

[–] ipkpjersi@lemmy.ml 5 points 4 weeks ago (1 children)

FWIW, I've found that the -v flag often doesn't say why it's not using your key, just that it isn't using your key and it has fallen back to password authentication.

It's usually not terribly helpful for figuring out why it's not using your key, just that it's not using your key, which you kind of already know if it's prompting you for a password. lol

[–] Scipitie@lemmy.dbzer0.com 2 points 3 weeks ago

Because it's basically axiomatic: ssh uses all keys it knows about. The system can't tell you why it's not using something it doesn't know it should be able to use. You can give a -i for the certificate to check if it doesn't know it because the content is broken or the location.

That said: this doesn't make -v more useful for cases like this, just because there's a reason!

[–] Tetsuo@jlai.lu 2 points 4 weeks ago (2 children)

Not OP but everytime I used the verbose output of ssh it didn't help me one bit. Even adding outrageous verbosity I was still quite confused on what step failed and which didn't.

I'm probably just bad at understanding SSH but i don't know it seems like ssh workflow includes many trial and error until it finds a way to connect.

Imo the verbose output of SSH is often not very helpful if you don't know very well ssh in the first place. Obviously it is still worth a shot and a good advice but don't expect ssh to clearly state what is going on :)

load more comments (2 replies)
[–] exu@feditown.com 22 points 4 weeks ago (1 children)

Maybe ssh can't find the key automatically. What is the path to your private key?

[–] dysprosium@lemmy.dbzer0.com 4 points 4 weeks ago (1 children)

I'm pretty sure I generated it to ~/.ssh/id_rsa which I think the default location. It is also the location shown in the terminal image in my post.

[–] Phrodo_00@lemmy.world 2 points 3 weeks ago

I think some distros disable using RSA by default. Might need to use it explicitly.

[–] flux@lemmy.ml 13 points 4 weeks ago (3 children)

As mentioned, -v (or -vv) helps to analyze the situation.

My theory is that you already have something providing ssh agent service, but that process is somehow stuck, and when ssh tries to connect it, it doesn't respond to the connect, or it accepts the connection but doesn't actually interact with ssh. Quite possibly ssh doesn't have a timeout for interacting with ssh-agent.

Using eval $(ssh-agent -s) starts a new ssh agent and replaces the environment variables in question with the new ones, therefore avoiding the use of the stuck process.

If this is the actual problem here, then before running the eval, echo $SSH_AUTH_SOCK would show the path of the existing ssh agent socket. If this is the case, then you can use lsof $SSH_AUTH_SOCK to see what that process is. Quite possibly it's provided by gnome-keyring-daemon if you're running Gnome. As to why that process would not be working I don't have ideas.

Another way to analyze the problem is strace -o logfile -f ssh .. and then check out what is at the end of the logfile. If the theory applies, then it would likely be a connect call for the ssh-agent.

[–] beeng@discuss.tchncs.de 6 points 4 weeks ago (1 children)
[–] flux@lemmy.ml 4 points 4 weeks ago

I guess it's worth checking if those names point to the expected binaries, but I also think it would be highly unlikely they would be anything else than just /usr/bin/ssh and /usr/bin/ssh-agent.

[–] smb@lemmy.ml 3 points 4 weeks ago (2 children)

My theory is that you already have something providing ssh agent service

in the past some xserver environments started an ssh-agent for you just in case of, and for some reason i don't remember that was annoying and i disabled it to start my agent in my shell environment as i wanted it.

also a possibility is tharlt there are other agents like the gpg-agent that afaik also handles ssh keys.

but i would also look into $HOME/.ssh/config if there was something configured that matches the hostname, ip, or with wildcards* parts of it, that could interfere with key selection as the .ssh/id_rsa key should IMHO always be tried if key auth is possible and no (matching) key is known to the ssh process, that is unless there already is something configured...

not sure if a system-wide /etc/ssh/ssh_config would interfere there too, maybe have a look there too. as this behaviour seems a bit unexpected if not configured specially to do so.

load more comments (2 replies)
[–] dysprosium@lemmy.dbzer0.com 2 points 4 weeks ago* (last edited 4 weeks ago) (2 children)

I didn't really follow the former part, but I can give you this:

strace -o logfile -f ssh -p 8322 pi@192.168.2.223 of when I get blank

[–] gedhrel@lemmy.world 6 points 4 weeks ago

Please don't ignore the advice about SSH_AGENT_SOCK. It'll tell yoy what's going on (but not why).

[–] flux@lemmy.ml 2 points 4 weeks ago (2 children)

At the end of the log you find:

822413 connect(4, {sa_family=AF_UNIX, sun_path="/run/user/1000/gcr/ssh"}, 110) = 0
...
822413 read(4, 

meaning it's trying to interact with the ssh-agent, but it (finally) doesn't give a response.

Use the lsof command to figure out which program is providing the agent service and try to resolve issue that way. If it's not the OpenSSH ssh-agent, then maybe you can disable its ssh-agent functionality and use real ssh-agent in its place..

My wild guess is that the program might be trying to interactively verify the use of the key from you, but it is not succeeding in doing that for some reason.

load more comments (2 replies)
[–] gedhrel@lemmy.world 7 points 4 weeks ago (1 children)

Without the ssh-agent invocation:

  • what does ssh-add -L show?
  • what is the original SSH_AUTH_SOCK value?
  • what is listening to that? (Use lsof)

This kind of stuff often happens because there's a ton of terrible advice online about managing ssh-agent - make sure there's none if that baked into your shellrc.

[–] dysprosium@lemmy.dbzer0.com 4 points 4 weeks ago* (last edited 4 weeks ago) (9 children)
ssh-add -L
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCqS5l(redacted)f0phb8x+fUV1w== username@computername
echo $SSH_AUTH_SOCK
/run/user/1000/gcr/ssh
lsof $SSH_AUTH_SOCK
COMMAND      PID    USER FD   TYPE             DEVICE SIZE/OFF    NODE NAME
gcr-ssh-a 778406 username  3u  unix 0x000000007e25ee6b      0t0   30290 /run/user/1000/gcr/ssh type=STREAM (LISTEN)
gcr-ssh-a 778406 username  6u  unix 0x0000000020f5b559      0t0 2096642 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 12u  unix 0x00000000a6756d60      0t0 2100347 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 15u  unix 0x00000000625cb05a      0t0 2261237 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 21u  unix 0x00000000d0b214f9      0t0 2261238 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 23u  unix 0x00000000a2f197fe      0t0 2349665 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 27u  unix 0x00000000da22a130      0t0 2349668 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 29u  unix 0x000000004f7a1723      0t0 2365382 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 33u  unix 0x00000000e26976b3      0t0 2365389 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 35u  unix 0x00000000b8185a8a      0t0 2375648 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 39u  unix 0x00000000ba41030c      0t0 2375649 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 41u  unix 0x000000006867cb01      0t0 2380999 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 45u  unix 0x0000000091384b95      0t0 2381008 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 47u  unix 0x00000000d5b28b08      0t0 3729149 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)
gcr-ssh-a 778406 username 51u  unix 0x00000000f65088aa      0t0 3731006 /run/user/1000/gcr/ssh type=STREAM (CONNECTED)

All before issuing the ssh-agent

[–] gedhrel@lemmy.world 4 points 4 weeks ago

It's the gnome key ring ssh agent.

It's possible that this has popped up a window asking gor permission / a passphrase / something and you're not seeing that.

load more comments (8 replies)
[–] netvor@lemmy.world 5 points 4 weeks ago (1 children)

please, it's eval "$(ssh-agent -s)" (quotes!)

[–] dysprosium@lemmy.dbzer0.com 1 points 4 weeks ago* (last edited 4 weeks ago) (3 children)

well seems to work without tho

edit: made no difference, but I changed it in the post title.

[–] Thorry84@feddit.nl 6 points 4 weeks ago

Just because it works, doesn't mean it's right.

[–] ede1998 3 points 4 weeks ago

I had a similar construct in my bashrc and forgot the quotes. It didn't throw an error but also didn't work. Took quite a while to find the issue. So personally, I would recommend trying to quote correctly whenever possible.

load more comments (1 replies)
[–] tetris11@lemmy.ml 2 points 4 weeks ago (1 children)

what are your ssh config settings: ~/.ssh/config or /etc/ssh/ssh_config

[–] dysprosium@lemmy.dbzer0.com 2 points 4 weeks ago* (last edited 4 weeks ago) (1 children)

I just added the ~/.ssh/config file on client side:

Host pidoos
     HostName 192.168.2.223
     User pi
     IdentityFile ~/.ssh/id_rsa

Same result.

The /etc/ssh/ssh_config is only relevant on the server side, right? Well, here it is.

[–] tetris11@lemmy.ml 1 points 4 weeks ago (1 children)

sshd_config is server side, ssh_config is client side AFAIK

Your config looks pretty tame. Anything interesting in /etc/ssh/config.d/ ?

load more comments (1 replies)
[–] hitmyspot@aussie.zone 2 points 4 weeks ago (1 children)

Where is the key? What are the permissions for it?

[–] dysprosium@lemmy.dbzer0.com 2 points 4 weeks ago (2 children)

it got 600 both the private and public key, stored in ~/.ssh/

load more comments (2 replies)
[–] mike_wooskey@lemmy.thewooskeys.com 2 points 4 weeks ago (1 children)

Can you try killall ssh on the client, and then try to ssh into the rpi again?

load more comments (1 replies)
[–] kolorafa@lemmy.world 1 points 3 weeks ago

The only reason ssh client would "hang" without any output is when it's waiting for external key storage to allow access. It's designed that way to give user some time to approve access to key storage.

It sometimes happen that the installed key storage is broken in a way that it fails to show user modal, for any reason (showing on wrong screen, wrong desktop, wrong activity, wrong framebuffer, ....)

One solution (that you already did) is to change the SSH agent env variable to point to different key storage.

Another would be (if possible) to uninstall the broken key storage if you don't use it. But it is sometimes needed/used by other apps.

It's overall good to notify/open bug on your distro issue tracker to notify that some packages are missconfigured (maybe have missing dependencies) or conflicts with other ones.

[–] boredsquirrel@slrpnk.net 1 points 4 weeks ago (1 children)

I have no idea why but ssh seems to not use keys with different names by default

[–] dysprosium@lemmy.dbzer0.com 1 points 4 weeks ago* (last edited 4 weeks ago) (1 children)

can you expand on that? What do you mean different names? My PC has of course a different username than the server I'm connecting to. The label name at the end of the key is just a comment, so this is also not what you're referring to, I think.

load more comments (1 replies)
[–] angel@sopuli.xyz 1 points 4 weeks ago

Try running ssh with -vv to get a better idea of the problem when no ssh agent is running.

[–] fuzzy_feeling@programming.dev 1 points 4 weeks ago (1 children)
load more comments
view more: next ›