Home > Mobile >  Can't add ssh key to the ssh agent
Can't add ssh key to the ssh agent

Time:09-26

I am trying to add my ssh key to the ssh agent but I always get the same error message, first I use root access by entering: sudo -s -H ,then I enter my password an continue typing the next line: eval "$(ssh-agent)" in order to start the ssh-agent. No error messages so far, everything done correctly. But the thing is that when I try to add the actual key with: ssh-add ~/.ssh/key-id (where key-id is replaced with the name of the key), I get this error message: /root/.ssh/key-id: No such file or directory.

Here is the entire process:

sudo -s -H
[sudo] password for nulaxz:
[root@nulaxz-ms7a33 nulaxz]# eval "$(ssh-agent -s)"
Agent pid 632477
[root@nulaxz-ms7a33 nulaxz]# ssh-add ~/.ssh/key-id
/root/.ssh/key-id: No such file or directory

I've tried using ssh-add ~/.ssh/key-id, ssh-add ~/key-id or ssh-add ~/.ssh/id-rsa/key-id just in case, but all of them return the same error message.

Maybe I saved it in another location and I don't know, if so, how can I check it?

My main goal with this, is to connect Git and GitHub, I have been working a long time without them and I recently discovered Git, which really makes life easier, so I want to jump into GitHub aswell, so if anyone came across this error in the past and knows how to solve it, please let me know how you did it ;)

CodePudding user response:

The problem is that your home directory (~) changes when you login as root, which means that you can't refer to the user's home directory just with the ~, but you have to specify the whole path (e.g., /home/yourusername/.ssh/key-id).

Just execute your commands with sudo privileges, without root access.

  • Related