Score:5

.ssh Directory has no id files after installing ssh service

tn flag

I installed Ubuntu 22.04 and activated ssh service using

sudo apt install ssh

I tried to connect to my Ubuntu from my Windows using ssh via putty and it worked. putty asked to trust Ubuntu's key and everything is good.

But if I go to Ubuntu and try to see the public and private keys that were generated when installing the ssh service, they aren't in the ~/.ssh/ directory.

Can anyone explain it, please?

Score:5
vn flag

There is a difference between connecting with SSH and generating SSH public and private keys. Be aware that the terminology in your question (public and private keys, "id files", ~/.ssh/) lead to thinking about user generated SSH keypairs.

The directory you're referring to (~/.ssh/) is for user generated SSH keypairs, known_hosts file etc., and installing SSH in itself will not generate a user keypair. If you want to connect with SSH keypairs from Windows, you need to do the following:

  • Create a SSH keypair on your Windows machine (off-topic here, but on-topic on Superuser)
  • Install the public key you generated on Windows on your Ubuntu machine

Here is a Q&A on Superuser that details how to setup SSH keys on Windows for use with PuTTY, and another one about why and how the keys are stored.

However, if you're referring to the SSH host keys that are generated when installing SSH, those are located inside /etc/ssh, and can be listed with this command:

$ ls -la /etc/ssh/ssh_host*
-rw------- 1 root root 1373 May  8  2020 /etc/ssh/ssh_host_dsa_key
-rw-r--r-- 1 root root  597 May  8  2020 /etc/ssh/ssh_host_dsa_key.pub
-rw------- 1 root root  492 May  8  2020 /etc/ssh/ssh_host_ecdsa_key
-rw-r--r-- 1 root root  169 May  8  2020 /etc/ssh/ssh_host_ecdsa_key.pub
-rw------- 1 root root  399 May  8  2020 /etc/ssh/ssh_host_ed25519_key
-rw-r--r-- 1 root root   89 May  8  2020 /etc/ssh/ssh_host_ed25519_key.pub
-rw------- 1 root root 2590 May  8  2020 /etc/ssh/ssh_host_rsa_key
-rw-r--r-- 1 root root  561 May  8  2020 /etc/ssh/ssh_host_rsa_key.pub

The public host key is saved on the client machine (as known_hosts) to verify the identity of the remote machine and mark the connection as "trusted". On Ubuntu, known hosts are saved in ~/.ssh/known_hosts (refer to Superuser when it comes to Windows).

Pilot6 avatar
cn flag
This question is not about connecting with ssh keys. Anytime you connect to something with ssh for the first times, some keys are generated. Even if you connect using a password. The question is what are these keys and where they are located. I am interested in an answer too. My guess is that the keys are at Windows side.
Artur Meinild avatar
vn flag
Yeah, they would be on Windows, and thus off-topic here.
hr flag
The OP is probably talking about the server's *host key*
Pilot6 avatar
cn flag
@ArturMeinild It is not really off-topic. Let's assume we are connecting from one Ubuntu to another. An answer about host keys would be useful.
Artur Meinild avatar
vn flag
Added location of SSH host keys
hr flag
The OP may also wish to know why they were asked to accept the key and [Where does Putty store known_hosts information on Windows?](https://superuser.com/questions/197489/where-does-putty-store-known-hosts-information-on-windows)
Keeran avatar
tn flag
Thank you guys. I got the answer and an good explanation. Thank you @ArturMeinild for the explanation again.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.