Forked from ThomasLeister/auto-start-tmux-ssh.txt
Last active
March 12, 2023 22:24
-
-
Save TechnologyClassroom/4aa84a1c929c8bb76acb391165bcb5d9 to your computer and use it in GitHub Desktop.
Put this into your .bashrc to auto-start a tmux session after SSH login
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
# Put these lines into your server's .bashrc: | |
## | |
## TMUX auto attach | |
## | |
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then # If this is an SSH session | |
if which tmux >/dev/null 2>&1; then # Check if tmux is installed | |
if [[ -z "$TMUX" ]] ;then # Do not allow "tmux in tmux" | |
ID="$( tmux ls | cut -d: -f1 | head -n 1 )" # Get the id of an existing session | |
if [[ -z "$ID" ]] ;then # If not available create a new one | |
tmux new-session | |
else | |
tmux attach-session -t "$ID" # If available, attach to it | |
fi | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment