Last active
September 30, 2024 05:01
-
-
Save zigforge/e62af5af929c21cc9e3f2e65ae06015b to your computer and use it in GitHub Desktop.
SSH setup on Mac
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
| #!/bin/bash | |
| # Function to check if a command exists | |
| command_exists() { | |
| command -v "$1" >/dev/null 2>&1 | |
| } | |
| # Install Homebrew if not already installed | |
| if ! command_exists brew; then | |
| echo "Installing Homebrew..." | |
| /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| else | |
| echo "Homebrew is already installed." | |
| fi | |
| # Install required packages | |
| echo "Installing required packages..." | |
| brew install tmux autossh mosh vim zsh rsync fzf bat tldr | |
| # Install Oh My Zsh | |
| if [ ! -d "$HOME/.oh-my-zsh" ]; then | |
| echo "Installing Oh My Zsh..." | |
| sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
| else | |
| echo "Oh My Zsh is already installed." | |
| fi | |
| # Set up tmux configuration | |
| echo "Setting up tmux configuration..." | |
| curl -o ~/.tmux.conf https://gist.githubusercontent.com/zigforge/fded5b2855263f95147108013171d3b8/raw/tmux.conf | |
| # Set up SSH config for easier connections | |
| echo "Setting up SSH config..." | |
| mkdir -p ~/.ssh | |
| cat << EOF >> ~/.ssh/config | |
| Host jump-server | |
| HostName your-jump-server.com | |
| User your-username | |
| ForwardAgent yes | |
| EOF | |
| # Create a script for autossh connection | |
| echo "Creating autossh connection script..." | |
| cat << EOF > ~/autossh_connect.sh | |
| #!/bin/bash | |
| autossh -M 0 -f -T -N jump-server | |
| EOF | |
| chmod +x ~/autossh_connect.sh | |
| # Create a script to set up tmux session | |
| echo "Creating tmux session setup script..." | |
| cat << EOF > ~/setup_tmux_session.sh | |
| #!/bin/bash | |
| tmux new-session -d -s remote_work | |
| tmux rename-window -t remote_work:1 'monitor' | |
| tmux send-keys -t remote_work:1 'htop' C-m | |
| tmux new-window -t remote_work:2 -n 'logs' | |
| tmux send-keys -t remote_work:2 'tail -f /var/log/system.log' C-m | |
| tmux new-window -t remote_work:3 -n 'editor' | |
| tmux send-keys -t remote_work:3 'vim' C-m | |
| tmux select-window -t remote_work:1 | |
| EOF | |
| chmod +x ~/setup_tmux_session.sh | |
| # Set up basic Vim configuration | |
| echo "Setting up basic Vim configuration..." | |
| cat << EOF > ~/.vimrc | |
| set number | |
| set ruler | |
| set incsearch | |
| set hlsearch | |
| set ignorecase | |
| set smartcase | |
| set expandtab | |
| set shiftwidth=4 | |
| set softtabstop=4 | |
| syntax on | |
| EOF | |
| # Add useful aliases and configurations to shell | |
| echo "Adding useful aliases and configurations to shell..." | |
| cat << EOF >> ~/.zshrc | |
| # Aliases | |
| alias cat='bat' | |
| # fzf configuration | |
| [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh | |
| # Custom prompt | |
| PROMPT='%F{green}%n@%m%f:%F{blue}%~%f$ ' | |
| # Add tldr to PATH | |
| export PATH=\$PATH:\$HOME/.tldr/bin | |
| # Use vim as the default editor | |
| export EDITOR='vim' | |
| export VISUAL='vim' | |
| EOF | |
| echo "Setup complete!" | |
| echo "To connect, run: ~/autossh_connect.sh" | |
| echo "Then, to set up your tmux session, run: ~/setup_tmux_session.sh" | |
| echo "Finally, attach to your tmux session with: tmux attach -t remote_work" | |
| echo "Remember to run source ~/.zshrc or restart your terminal to apply the new configurations." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment