Persist the SSH agent and the added key across terminal sessions by using the `ssh-agent` service.

If you want to persist the SSH agent and the added key across terminal sessions by using the `ssh-agent` service.

 

1. Open a terminal.

 

2. Run the following command to start the `ssh-agent` service:

   eval "$(ssh-agent -s)"

 

 

3. Add your SSH key to the agent by running:

   ssh-add ~/.ssh/id_ed25519

 

4. Next, create or modify the SSH configuration file by running:

   nano ~/.ssh/config

 

5. Add  key into Authorized keys:

cat .ssh/id_ed25519.pub   >> .ssh/authorized_keys'



 

5. In the text editor, add the following lines to the file:

      Host *
     AddKeysToAgent yes
     IdentityFile ~/.ssh/id_ed25519

 

This configuration enables the agent to automatically load the SSH key when needed.

 

6. Save the changes and exit the text editor (in nano, press Ctrl+X, then Y, then Enter).

 

From now on, whenever you start a new terminal session, the `ssh-agent` service should automatically be running, and your SSH key should be loaded into the agent. You won’t need to manually run `eval “$(ssh-agent -s)”` and `ssh-add` each time.

 

Note: This method assumes you’re using the OpenSSH client. If you’re using a different SSH client, the steps may vary.

 

 

https://github.com/appleboy/ssh-action#setting-up-ssh-key

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *