SSH Menu (sshm)
A standalone Bash script providing an interactive SSH menu for connecting to hosts defined in your ~/.ssh/config. The script, sshm.sh, parses SSH configurations, validates environment prerequisites, and presents a user-friendly selection interface—all in a single file.
-- Small, simple, and effective! Out of all the scripts I have written, this is the one I use the most. It is a single file that works on both macOS and Linux. It is a great way to quickly SSH into servers without having to remember their hostnames or IP addresses.
- Parses your
~/.ssh/configto list known hosts. - Interactive menu to select and SSH into a host.
- Option to display the entire SSH config.
- Single-file implementation for easy installation.
- Cross-platform support (Linux & macOS).
- Operating System: macOS or Linux (requires Bash).
- SSH: Ensure the
sshcommand is installed and available in your$PATH. - Permissions: Read/write access to your SSH config file (
~/.ssh/config).
-
Clone this repository or download the script:
git clone https://github.com/yousefabuz17/SSHMenu.git cd sshm -
Ensure the script is executable:
chmod +x sshm.sh
-
(Optional) Move it to a directory in your
$PATH, e.g.:mv sshm.sh /usr/local/bin/sshm
The script relies on your SSH configuration file located at ${HOME}/.ssh/config. A sample entry in the config:
Example `~/.ssh/config` entry
Host myserver
HostName server.example.com
User gituser
Port 22
.....
Host anotherserver
HostName another.example.com
User anotheruser
Port 2222
.....
Multiple Host entries can be defined; each will appear as a menu option.
Run the script without arguments to see an interactive menu:
- The script checks your OS, SSH binary, and the SSH config file.
- It parses the
~/.ssh/configand lists all known hosts. - Select a host by its number.
- The script connects via
ssh <host>. - Upon exit, the menu is re-displayed.
./sshm.sh
# or if installed globally
sshm
Select a server to SSH into:
1) Root-Centos7-Linux 4) Root-MacbookPro 7) Kali-Linux
2) Root-Kali-Linux 5) Root-Rocky-Linux 8) MacbookPro-MeshNet
3) Rocky-Linux 6) MacbookPro 9) Centos7-Linux
Server #: <number>
# After selecting a server, it will connect via SSH while requesting your password if necessary.
To print the contents of your SSH config and exit:
./sshm.sh -d
# or
./sshm.sh --displayThe sshm.sh script includes all helper functions inline:
-
Environment Checks:
check_machine()— Ensures OS isdarwin(macOS) orlinux.check_ssh()— Verifies thesshbinary is available.ssh_config()— Confirms that~/.ssh/configexists and is readable.
-
Config Parsing:
parse_config()— ReadsSSH_CONFIG_FILE, extractsHostentries into an array.
-
Menu & Arguments:
parse_arguments()— Handles-d/--displayflag.sshMenu()— Displays an interactive prompt (usingselect) to choose a host.
-
Main Flow:
parse_arguments "$@"to check for display mode.- If display flagged, show config and exit.
- Otherwise, run
sshMenu.