-
-
Save jimblue/202d9434bc0bc55d34da626ba674452e to your computer and use it in GitHub Desktop.
Revisions
-
lukasnellen revised this gist
May 29, 2019 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,18 @@ #! /bin/bash # This is ~/.ssh/rc (remote) # for X11 forwarding - needed, since the rc files hides default behaviour if read proto cookie && [ -n "$DISPLAY" ]; then if [ `echo $DISPLAY | cut -c1-10` = 'localhost:' ]; then # X11UseLocalhost=yes echo add unix:`echo $DISPLAY | cut -c11-` $proto $cookie else # X11UseLocalhost=no echo add $DISPLAY $proto $cookie fi | xauth -q - fi # Setup standard ssh socket link if [ ! -S $HOME/.ssh/ssh_auth_sock -a -S "$SSH_AUTH_SOCK" ]; then ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock fi -
lukasnellen revised this gist
Jun 2, 2018 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,3 +38,8 @@ You might want to set up two shorthands, one for normal ssh accesses and one for ## Automatic ssh-agent socket handling and renewal The socket of the ssh agent to access the unlocked keys changes with every ssh login. You loose access to your ssh keys when you re-attach to your tmux session. To avoid this, we can link the current authentication socket to a well-known name. We use `~/.ssh/ssh-auth-sock`. This link can be set and updated in `~/.ssh/rc`, see the `ssh--rc` example below. To use this name, set the `SSH_AUTH_SOCK` environment variable in your `~/.tmux.conf` file, see the `tmux.conf` example below. **NB** Your global `sshd` configuration might prohibit the use of the `~/.ssh/rc` file. This is controlled by the administrator of the remote host. **NB** The `~/.ssh/ssh-auth-sock` gets set if it doesn't point to a valid socket. This means it might not point to the authentication socket of the ssh session running your tmux session if you have an earlier, regular ssh session open. If that is the case, the socket connection will be lost the moment you log out from that session. -
lukasnellen revised this gist
Jun 2, 2018 . 2 changed files with 18 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,27 +8,33 @@ This is a compilation of information I found in different postings on the net. `tmux` can be invoked in command mode using `tmux -CC`. The simplest way to get a remote tmux session into a window of iterm is to invoke it on the remote host ``` local> ssh rmhost #... rmhost> tmux -CC ``` This will open a new tmux session in a new iterm window. ### Invoke tmux as the command to ssh To run `tmux` as the remote command argument to `ssh`, it need a pseudo-terminal attached. This means invoking `ssh` with the `-t` flag: ``` local> ssh rmhost -t tmux -CC ``` ### Naming the remote session to be able to re-attach If you want to re-attach to a remote session, you have to know its name. The easisest way to is to create a session with a well known name and re-attach to that session later. For that, we invoke `tmux` with the command `new -A -s tmux-main`. The session name is set using the `-s` flag, the `-A` flag specifies that `new` behaves like `attach` if the session exists. The command is now ``` local> ssh rmhost -t tmux -CC new -A -s tmux-main ``` ## Setting up a host configuration The final command we put together above is a much on the fingers if you use it a lot. The solution is either to set up a shell alias or a special `Host` configuration in your `~./.ssh/config` file, as shown below in `ssh--config`. If you do that, the command to invoke becomes ``` local> ssh tmhost ``` You might want to set up two shorthands, one for normal ssh accesses and one for ssh with tmux. ## Automatic ssh-agent socket handling and renewal This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,14 @@ # This is a fragment of ~/.ssh/config (local) # regular ssh shorthand for remote host Host rmhost HostName remote.host.some.where ### fix host name ### more ssh options here are needed # ssh shorthand for remote host with tmux invocation Host tmhost HostName remote.host.some.where ### fix host name ForwardAgent yes RemoteCommand tmux -CC new -A -s tmux-main RequestTTY yes ### more ssh options here are needed -
lukasnellen revised this gist
Jun 2, 2018 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,6 @@ This is a compilation of information I found in different postings on the net. ### Basic remote tmux session `tmux` can be invoked in command mode using `tmux -CC`. The simplest way to get a remote tmux session into a window of iterm is to invoke it on the remote host ``` local> ssh tmhost #... @@ -22,6 +21,13 @@ To run `tmux` as the remote command argument to `ssh`, it need a pseudo-terminal local> ssh tmhost -t tmux -CC ``` ### Naming the remote session to be able to re-attach If you want to re-attach to a remote session, you have to know its name. The easisest way to is to create a session with a well known name and re-attach to that session later. For that, we invoke `tmux` with the command `new -A -s tmux-main`. The session name is set using the `-s` flag, the `-A` flag specifies that `new` behaves like `attach` if the session exists. The command is now ``` local> ssh tmhost -t tmux -CC new -A -s tmux-main ``` ## Setting up a host configuration ## Automatic ssh-agent socket handling and renewal -
lukasnellen revised this gist
Jun 2, 2018 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,13 +4,23 @@ This is a compilation of information I found in different postings on the net. ## All manual invocation ### Basic remote tmux session `tmux` can be invoked in command mode using `tmux -CC`. The simplest way to get a remote tmux session into a window of iterm is to invoke it on the remote host ``` local> ssh tmhost #... remote> tmux -CC ``` This will open a new tmux session in a new iterm window. ### Invoke tmux as the command to ssh To run `tmux` as the remote command argument to `ssh`, it need a pseudo-terminal attached. This means invoking `ssh` with the `-t` flag: ``` local> ssh tmhost -t tmux -CC ``` ## Setting up a host configuration -
lukasnellen revised this gist
Jun 2, 2018 . 3 changed files with 19 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ # Configuration to use remote tmux over ssh in iterm This is a compilation of information I found in different postings on the net. ## All manual invocation `tmux` can be invoked in command mode using `tmux -CC`. The simplest way to get a remote tmux session into a window of iterm is to invoke it on the remote host ``` local> ssh tmhost #... remote> tmux -CC ``` ## Setting up a host configuration ## Automatic ssh-agent socket handling and renewal This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ # This is a fragment of ~/.ssh/config (local) Host tmhost HostName remote.host.some.where ForwardAgent yes RemoteCommand tmux -CC new -A -s tmux-main -
lukasnellen renamed this gist
Jun 1, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
lukasnellen revised this gist
Jun 1, 2018 . 3 changed files with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes. -
lukasnellen renamed this gist
Jun 1, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
lukasnellen created this gist
Jun 1, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # This is a fragment of ~/.ssh/config (local) Host tmux HostName remote.host.some.where ForwardAgent yes RemoteCommand tmux -CC new -A -s tmux-main RequestTTY yes This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ #! /bin/bash # This is ~/.ssh/rc (remote) if [ ! -S $HOME/.ssh/ssh_auth_sock -a -S "$SSH_AUTH_SOCK" ]; then ln -sf $SSH_AUTH_SOCK ~/.ssh/ssh_auth_sock fi This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ # This is ~/.tmux.conf (remote) set -g update-environment "DISPLAY SSH_ASKPASS SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY" set-environment -g 'SSH_AUTH_SOCK' $HOME/.ssh/ssh_auth_sock set -g set-titles on # not all distros have a tmux terminal type #set -g default-terminal tmux set -g default-terminal xterm-color This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # Configuration to use remote tmux over ssh in iterm