User Tools

Site Tools


software:ssh_config

Differences

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

Link to this comparison view

software:ssh_config [2026/07/27 08:07] – created solarsoftware:ssh_config [2026/07/27 08:25] (current) solar
Line 29: Line 29:
  
 Instead of having to write ''MyHostUser1234@MyHost.example.com:8022'', all you need to write now is ''MyHost''. Instead of having to write ''MyHostUser1234@MyHost.example.com:8022'', all you need to write now is ''MyHost''.
 +
 +==== ssh-agent ====
 +
 +One thing you cannot -- and indeed should not -- write into a config file is the pass phrase for your private key. Neither should you use a private key //without// a pass phrase. Instead, you should set up a key agent: A process that takes your passphrase //once//, unlocks your private key with it, and keeps it available until you log out again.
 +
 +SSH comes with one such key agent included -- ''ssh-agent''. Unfortunately many setup tutorials are rather basic, telling you to just ''eval $(ssh-agent)''. Yes, that works, but if you put that into your shell profile, you will spawn another agent  //every time you open a new shell//. Instead, add a bit of extra logic that 1) tracks any agent you already launched, and 2) launches a new one only if necessary, re-using the already-running process wherever possible:
 +
 +<code>
 +start_agent() {
 +    mkdir -p "$(dirname "$SSH_ENV")"
 +    ssh-agent -s > "$SSH_ENV"
 +    chmod 600 "$SSH_ENV"
 +    . "$SSH_ENV" >/dev/null
 +}
 +
 +agent_is_usable() {
 +    [ -n "$SSH_AGENT_PID" ] &&
 +    kill -0 "$SSH_AGENT_PID" 2>/dev/null &&
 +    [ -n "$SSH_AUTH_SOCK" ] &&
 +    [ -S "$SSH_AUTH_SOCK" ]
 +}
 +
 +if [ -f "$SSH_ENV" ]; then
 +    . "$SSH_ENV" >/dev/null
 +fi
 +
 +if ! agent_is_usable; then
 +    start_agent
 +fi
 +</code>
 +
 +Now, when you need SSH the first time, call ''ssh-add'', which adds your private key to the agent's "keychain". You will be asked for your passphrase this one time. Any subsequent use of SSH in the same login session will use the agent's keychain; you won't need to enter your pass phrase a second time.
 +
 +Many passkey managers have some kind of SSH agent integration, but this is not the place to discuss their respective setups.
  
 ==== Bottom Line ==== ==== Bottom Line ====
  
 If you have set up your SSH environment correctly, copying a file from local to remote becomes as easy as ''scp <oldfile> MyHost:~/<newfile>''. If you have set up your SSH environment correctly, copying a file from local to remote becomes as easy as ''scp <oldfile> MyHost:~/<newfile>''.
software/ssh_config.txt · Last modified: by solar

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki