Simplify your workflow with key-based SSH access! This script automatically sets up your remote server so that, once configured, you can connect without entering a password. After running the setup, simply use:
ssh {serverName}Replace {serverName} with the alias you chose during setup, and enjoy an automatic, secure login.
- Single SSH Key:
Utilizes one RSA key pair for all servers. - Automatic SSH Config:
Adds or updates your SSH configuration file so you can connect via server aliases. - Key Deployment:
Automatically copies your public key to the target server if key-based authentication is not already set up. - Portability:
Designed to work on both macOS and Linux.
- Bash
- ssh, ssh-keygen, and ssh-copy-id (usually available on Unix-like systems)
-
Clone this repository:
git clone https://github.com/ehzack/ssh-server-setup.git cd ssh-server-setup -
Make the script executable:
chmod +x setup_ssh.sh
Run the script with the following parameters:
./setup_ssh.sh <server_alias> <server_ip> <username>After running the script:
-
A new RSA key pair is generated (if not already available).
-
Your public key is deployed to the server.
-
Your SSH configuration is updated so that you can simply type:
ssh <server_alias>
to log in automatically without a password.
- SSH Key Generation:
The script checks for an existing RSA key (~/.ssh/server_id_rsa). If it doesn't exist, a new 4096-bit RSA key pair is created. - Public Key Deployment:
It usesssh-copy-idto copy your public key to the remote server, enabling key-based authentication. - SSH Config Update:
An entry is added or updated in your~/.ssh/configfile that maps your server alias to the server's hostname, username, key file, and port.
Contributions, bug reports, and feature requests are welcome! Please open an issue or submit a pull request via GitHub Issues.
This project is licensed under the MIT License. See the LICENSE file for details.