How to know what details Ubuntu is using for SSH host?

On Ubuntu 23.10, when I open a terminal and ssh in to a host I have like this:

ssh hostname.here.com

It logs me in straight away (even when I’ve first booted up my machine, not just after I’ve logged in for the frist time in a session). I have no details for the host in my ~/.ssh/config file either.

Now I need to work out what the username/password (and maybe the key file name) is for that host. I have a record but it’s a bit confused (and so far no username/password combination works – but that’s another matter).

I have looked at Seahorse, but it doesn’t seem to list anything obvious for the host.

How do I find out at least what username and/or key file Ubuntu is using to log in to it? Is there something else Ubuntu uses for remembering terminal logins?

Asked By: TommyPeanuts

||

How do I find out at least what username and/or key file Ubuntu is using to log in to it? Is there something else Ubuntu uses for remembering terminal logins?

Use the -v optipn (1,2,3,4, or 5 times for more and more details):

ssh -vvvvv hostname.here.com

will show almost every detail about the connection. Including username, encryption used (and where it found the user; and at that location you shpuld also find the password)

Username can come from .ssh/config but can be overwritten by setting
SSH_DEFAULT_USER (often used in .bashrc.

Username will be shown somewhere at the beginning in the form of

debug1: Authenticating to {host} as {user}

(-v will show the user too)

If you do not provide a user it likely is using your current user. Otherwise it should error out. And in that case it also will ask you for the password.

Answered By: Rinzwind

I failed to read this sentence in your question:

even when I’ve first booted up my machine, not just after I’ve logged in for the frist time in a session

So if that’s the case, this answer won’t help, as it assumes at least "something" has been done on the client, at some point; however, I’ll leave this answer in for those stumbling upon the same issue when using public-key authentication.


Most likely you’re logging in using public-key authentication.

Assuming the public-key authentication has been setup using ssh-copy-id (this is not the only way it could’ve been done), on the remote host, look at the contents of ~/.ssh/authorized_keys; there should be at least one entry that looks like so:

ssh-rsa xxxxxxxxxx user@hostname

where user@hostname is your local username / hostname (rsa may be something else).

Since you’re connecting without specifying a username, unless something in ~/.ssh/config is overriding this, the session’s username will default to your local user’s username; hence you’re probably logging in to the server using your local user’s username (to find out for sure, you could list the remote user’s username on the remote host by running whoami while logged in to the remote host).

As for the remote user’s password on the remote host, it’s not stored in cleartext anywhere (hopefully), and you can only attempt to guess it, but if the purpose to recover it is to just keep track of it / log in to the server from other machines without setting up public-key authentication for those machines, you may as well just change it to whatever you want:

passwd

At this point you should have everything figured out, and you should be able to log in to the server from other machines using:

ssh user@hostname.here.com

replacing user with your remote user’s username and by typing in the new password.

Answered By: kos
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.