0

Using an Ubuntu server, I have the following user:

uid=1001(githubactions) gid=1001(githubactions) groups=1001(githubactions),27(sudo),33(www-data),998(docker)

logged in as this user, I create a ssh key pair with `ssh-keygen -t rsa -b 4096 -C "githubactions key" -f ~/.ssh/githubactions

When I run git clone [email protected]:user/repo.git I get: [email protected]: Permission denied (publickey)

Github has a very good article about that issue. When I run ssh-add -l -E sha256 I get Could not open a connection to your authentication agent..

Next, I add my private key to my ssh agent:

> eval "$(ssh-agent -s)"
Agent pid 1022567
> ssh-add ~/.ssh/githubactions
Enter passphrase for /home/githubactions/.ssh/githubactions: 
Identity added: /home/githubactions/.ssh/githubactions (githubactions key)

I am now able to clone the repo. And now here is my issue: When I log out and back in, I am again not able to clone the repo using ssh with the error [email protected]: Permission denied (publickey) again.

Do I maybe have this issue, because I renamed my files and don't use id_rsa?

The user must be able re-use the key after logout, as I want to use it to pull the repo remotely using GitHub actions.

Peter Pan
  • 1
  • 2
  • Are you aware `eval "$(ssh-agent -s)"` sets some variables in your current shell and exports them to the environment? Even if the agent survives your logging out (it may or may not survive), a new shell (after logging in again) has no means to know these variables. They are crucial if you want anything to communicate with the agent automatically. Can you use `tmux` on the server to keep a shell (holding the variables) running? – Kamil Maciorowski Jul 11 '22 at 12:06
  • I could, but even as I am not a linux expert at all, this seems to be a workaround to me. Is having an extra user for that task unusual? I am not familiar with the ssh-agent or eval at all. I just took these commands from the instructions of GitHub. – Peter Pan Jul 11 '22 at 12:11
  • See the second part of [this answer](https://unix.stackexchange.com/a/132117/108618). It should work, unless something (possibly systemd `KillUserProcesses=yes`) kills all your processes when you log out. – Kamil Maciorowski Jul 11 '22 at 12:32
  • I added the code to `~/.profile` with no effect. What changes is the message after I ran `ssh-add -l -E sha256`: `The agent has no identities.`. `KillUserProcesses` is commented in `/etc/systemd/logind.conf`. – Peter Pan Jul 11 '22 at 14:09
  • When I add the private key to the ssh-agent it is working, but after logout and in, it is not working again. – Peter Pan Jul 11 '22 at 14:15
  • [This](https://superuser.com/q/564926/432690) maybe. – Kamil Maciorowski Jul 11 '22 at 14:20
  • Using in interactive shell explicitly has no noticeable effect – Peter Pan Jul 11 '22 at 14:38

0 Answers0