Score:1

How to install ssh keychain on Ubuntu with WSL

in flag

Please help me understand how to install ssh keychain on my Ubuntu under WSL in order for me to be able to configure my .ssh/config file to use key chain. I've tried editing my config file that I created myself in my .ssh folder to add Usekeychain but it does not recognise that as a command.

I tried uninstalling my ssh server and re-installing it manually but nothing changed. I just got stuck in adding my private/public key to my keychain ever since.

The whole essence of what I'm doing is to be able to connect to my server from my private computer without having to add my private key each time I want to login to my server but I'm stuck on how to go about it. Where I'm learning from online the person has his config file set up like:

Host*
    AddKeysToAgent Yes
    UseKeychain Yes
    IdentityFile ~/.ssh/[his githubfile]

Then I tried putting that in my config file, but when I tried login in to my server it said UseKeychain is not a command. Since then, I've since been trying to find how to add my key to my keychain and how to setup my config file. Until I encountered this problem, I had been able to setup my server and connect to it by installing my private key in the server each time I connect to it.

I just don't know how to go about adding my key to the keychain and how to setup my ssh config file to be automated. My teacher on front-end masters is using Metatron CLI.

I'm just confused and stressed. My first time on backend and it's becoming really frustrating, from one issue to another. My previous issues were because I'm using WSL.

Please help me on this. Thanks!

user535733 avatar
cn flag
Please try to use the correct terms. Seems like you are asking how to add your public key to a server. However maybe you are not, because "keyrings" and "config file" might mean that you are trying to do something else entirely. We cannot give you a clear answer to an unclear question.
ar flag
it is not clear what you are trying to do. Please [edit your question](https://askubuntu.com/posts/1356352/edit) and add the following information. Are you trying to setup SSH so that you can be somewhere else and access the WSL from another computer? Or are you trying to setup SSH so that you can sit in front of the WSL and connect to a computer far away?
Score:1
vn flag

Part of your problem, at least, is that UseKeychain is a MacOS-specific configuration option which instructs it to add the unlocked key to the MacOS Keychain (part of that OS that can store it securely). So we can assume that your instructor is on a Mac. It sounds like the Mac version of ssh will read the OS keychain, which is typically unlocked on first use across the whole OS. My understanding is that there are equivalents under Ubuntu, like Gnome Keyring, but this won't work under WSL.

So let's start with the fact that you'll need to remove that MacOS-specific configuration option under Ubuntu, at least.

If your instructor is providing that config file to students as an example, they really should do it properly with:

Host*
    IgnoreUnknown UseKeychain    
    AddKeysToAgent Yes
    UseKeychain Yes
    IdentityFile ~/.ssh/[his githubfile]

That would allow it to work both on a Mac as well as the (90%+) rest of the world.

Under WSL Ubuntu, you will need to enter the passphrase at least once in each session to add it to ssh-agent. If you run multiple shell instances, you'll typically need a new ssh-agent invocation in each shell.

Alternatively, you can install Funtoo keychain which can (more) easily set up the connection to ssh-agent in each shell instance. This can allow you to only need to enter the passphrase once as long as the WSL instance is working.

sudo apt-get install keychain

And add something like the following to your ~/.bashrc:

eval `keychain --eval --agents ssh id_rsa`

See the official keychain website for full instructions.

Please note, once the WSL Ubuntu instance terminates (wsl -l -v shows "Stopped") then the passphrase will need to be entered again on next use.

Abayomi Usman avatar
in flag
Thank you so much I have been able to add my key to the keychain and it's now running thank you so much! So that means I don't need to create a config file in my .ssh folder, am I right?
NotTheDr01ds avatar
vn flag
@AbayomiUsman True, with `keychain` set up, that particular config file doesn't add anything for your scenario, so you can leave it out.
Score:0
us flag

I'm assuming you trying to create a key pair and add it to you ssh-agent if so here are your instructions. If not We are all going to need more information.

Simplest instructions.

  1. cd ~/.ssh
  2. ssh-keygen (answer the corresponding questions) Now we need to add the key to ssh-agent
  3. eval ssh-agent -s
  4. ssh-add nameOfYourKey

now you have a key your system can use. export it to your remote system and setup your config file

Abayomi Usman avatar
in flag
That is my root problem, setting up my config file, please teach me how to. adding my key to my ssh-agent was my secondary problem and you just instructed me on what to do, but before i can do anything on that now, i don't know if it's my public key i'm supposed to add to the ssh-agent or my private key. Also the whole essence of what i'm doing is to be able to connect to my server from my private computer without having to add my private key each time i want to login to my server
Abayomi Usman avatar
in flag
ssh-agent -s SSH_AUTH_SOCK=/tmp/ssh-bqzi9yz6mZsX/agent.16952; export SSH_AUTH_SOCK; SSH_AGENT_PID=16953; export SSH_AGENT_PID; echo Agent pid 16953; abayomi@AbayomiUsman:~/.ssh$ ssh-add balfyp Could not open a connection to your authentication agent.
Abayomi Usman avatar
in flag
That's what i got when tried to follow the instructions you have just given me, i couldn't successfully add the private key, i tried adding public key instead i got the same error.
Bradley Armstrong avatar
us flag
here is a YouTube video to walk you through all of it https://www.youtube.com/watch?v=5JvU9wcZSbA&list=PLT98CRl2KxKGXz6l_5mpNKi-vJyR4MQ4e&index=2
TWA avatar
fr flag
TWA
If you are trying to put this in your .bashrc (or .zshrc, etc) put backticks around the eval command, and this should work. Like this, eval \`ssh-agent -s\`
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.