User Tools

Site Tools


networking:ssh:multiple-systemd-ssh-agents

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
networking:ssh:multiple-systemd-ssh-agents [2022/05/07 01:49] – created chucknetworking:ssh:multiple-systemd-ssh-agents [2022/05/07 02:00] (current) – [Manage the ssh-agent service] chuck
Line 56: Line 56:
 ---- ----
  
 +=====Administration=====
 +
 +====Manage the ssh-agent service====
 +  * Start and enable the agent as your regular user (and similar for the other agent(s)):<code bash>
 +systemctl --user enable --now ssh-agent@<name>.service
 +</code>
 +  * Check status of the ssh-agent service:<code bash>
 +systemctl --user status ssh-agent@<name>.service
 +</code>
 +  * Stop the ssh-agent service:<code bash>
 +systemctl --user stop ssh-agent@<name>.service
 +</code>
 +
 +===Naming the ssh-agent services===
 +  * Whatever name you use for each service will be included in the name of the agent's socket.
 +  * For example, if we named one ''%%foo%%'' and another ''%%bar%%'':<code bash>
 +systemctl --user enable --now [email protected]
 +systemctl --user enable --now [email protected]
 +</code>
 +  * We would have two new socket files:<code bash>
 +"$XDG_RUNTIME_DIR/foo-agent.socket"
 +"$XDG_RUNTIME_DIR/bar-agent.socket"
 +</code>
 +
 +----
 =====Set a default ssh-agent===== =====Set a default ssh-agent=====
   * Create an environment variable in your preferred startup file (eg ''%%~/.profile%%'', ''%%~/.bash_profile%%'', etc):<code bash>   * Create an environment variable in your preferred startup file (eg ''%%~/.profile%%'', ''%%~/.bash_profile%%'', etc):<code bash>
Line 86: Line 111:
 ---- ----
  
-=====Administration===== 
-====Manage the ssh-agent service==== 
-  * Start and enable the agent as your regular user (and similar for the other agent(s)):<code bash> 
-systemctl --user enable --now ssh-agent@<name>.service 
-</code> 
-  * Check status of the ssh-agent service:<code bash> 
-systemctl --user status ssh-agent@<name>.service 
-</code> 
-  * Stop the ssh-agent service:<code bash> 
-systemctl --user stop ssh-agent@<name>.service 
-</code> 
  
----- 
  
 ====Manage the keys in the ssh-agent==== ====Manage the keys in the ssh-agent====
   * For the default ssh-agent, running only the commands will work:   * For the default ssh-agent, running only the commands will work:
-    * List keys in the ssh-agent:<code bash> 
-ssh-add -L 
-</code> 
     * Add keys to the agent:<code bash>     * Add keys to the agent:<code bash>
 ssh-add ~/.ssh/ed_25519 ssh-add ~/.ssh/ed_25519
 +</code>
 +    * List keys in the ssh-agent:<code bash>
 +ssh-add -L
 </code> </code>
     * Clear keys from the agent:<code bash>     * Clear keys from the agent:<code bash>
Line 112: Line 125:
 </code> </code>
   * Prepend the command with the environment variable to access other ssh-agents:   * Prepend the command with the environment variable to access other ssh-agents:
-      * List keys in the ssh-agent:<code bash> 
-SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/<name>-agent.socket" ssh-add -L 
-</code> 
       * Add keys to the agent:<code bash>       * Add keys to the agent:<code bash>
 SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/<name>-agent.socket" ssh-add ~/.ssh/work SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/<name>-agent.socket" ssh-add ~/.ssh/work
 +</code>
 +      * List keys in the ssh-agent:<code bash>
 +SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/<name>-agent.socket" ssh-add -L
 </code> </code>
       * Clear keys from the agent:<code bash>       * Clear keys from the agent:<code bash>
Line 147: Line 160:
 ExecStart=-/usr/bin/ssh-agent -D -a %t/%i-agent.socket ExecStart=-/usr/bin/ssh-agent -D -a %t/%i-agent.socket
 </code> </code>
-  * //Currently untested//: Enable linger for users who need the agents to be active while not logged in+  * //Currently untested//: Enable linger for users who need the agents to be active while not logged in:<code bash>
-    * For example a backup user:<code bash>+
 loginctl enable-linger <user> loginctl enable-linger <user>
 </code> </code>
networking/ssh/multiple-systemd-ssh-agents.1651888175.txt.gz · Last modified: by chuck