20220116-ssh-aring_is_caring.md (1325B)
1 Have you ever logged on to a server over SSH and had to type in your really long and complicated password (let us assume for some reason you haven't configured SSH keys and a key agent), then wanted to open a second connection to that same server only to type your long and complicated password again? 2 3 What a pain in the ass. 4 5 Did you know that you can 'share' SSH sessions? 6 7 By using the `ControlMaster` and `ControlPath` config options you can open a session to a server using your long and complicated password, then every subsequent session to the same server shares the connection... no more password typing. 8 9 In your ~/.ssh/config add the following 10 ``` 11 Host * 12 ControlMaster auto 13 ControlPath ~/.ssh/%r@%h:%p 14 ``` 15 16 * `%r` - remote username 17 * `%h` - remote hostname 18 * `%p` - remote port 19 20 Further information on these and other options can be found in the ssh_config(5) man page. 21 22 This session sharing will work until the initial connection is closed, after which all subsequent connections will close, so be careful. 23 24 If you would rather the initial connection remain open in the background you can add the following to ~/.ssh/config 25 ``` 26 ControlPersist yes 27 ``` 28 29 You will have to kill or close that connection using an alternative method, e.g. `ssh -O exit`. 30 31 Read the ssh_config(5) man page for further information.