Last active
March 19, 2026 14:50
-
-
Save jayme-github/009af36d5635ab90114f2750bb0be3db to your computer and use it in GitHub Desktop.
Create/Attach tmux session on ssh
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 characters
| # Place this at the end of the ssh config to launch a tmux session called 'ssh' when logging in via SSH or attach to it when it exists. | |
| # * Don't launch tmux then ssh is called with a command (like 'ssh <remote> <command>') | |
| # * If tmux is not installed, fall back to the login shell | |
| # * Print the MOTD message in a temporary split-window on creating/attaching a session (will close on enter key) | |
| Match exec "[[ $(ps h o args p $PPID | wc -w) -eq 2 ]]" | |
| RequestTTY yes | |
| RemoteCommand command -v tmux > /dev/null 2>&1 && tmux new-session -A -s ssh \; split-window 'motd=$(cat /run/motd.dynamic 2>/dev/null || cat /etc/motd 2>/dev/null); lines=$(echo "$motd" | wc -l); tmux resize-pane -y $((lines + 1)); echo "$motd"; read -r _' || exec $SHELL -l |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment