Created
December 15, 2023 12:17
-
-
Save Coyas/76502ec45e3a7ed3ccf666e481f7d32f to your computer and use it in GitHub Desktop.
Create ssh account
This file contains 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 | |
# Check if required arguments are provided | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: $0 <remote_user> <remote_host>" | |
exit 1 | |
fi | |
# Assign command line arguments to variables | |
REMOTE_USER="$1" | |
REMOTE_HOST="$2" | |
SSH_KEY_PATH="~/.ssh/id_rsa" # Change this to your desired path | |
# Check if SSH key exists, generate if not | |
if [ ! -f "$SSH_KEY_PATH" ]; then | |
echo "Generating SSH key..." | |
ssh-keygen -t rsa -b 2048 -f "$SSH_KEY_PATH" | |
fi | |
# Add SSH key to SSH agent | |
eval "$(ssh-agent -s)" | |
ssh-add "$SSH_KEY_PATH" | |
# Test SSH connection | |
echo "Testing SSH connection..." | |
ssh "$REMOTE_USER@$REMOTE_HOST" | |
Advertisement | |
Add Comment | |
Please, Sign In to add comment | |
Advertisement | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment