SSH Setup
Overview
This skill helps configure SSH key-based authentication. It handles:
- •Checking for an existing local SSH key pair.
- •Generating a new key pair if none exists.
- •Copying the public key to a specified remote host.
Instructions
- •
Check for Local Key:
- •Look for SSH keys in the user's
.sshdirectory (e.g.,~/.ssh/id_ed25519.pubor~/.ssh/id_rsa.pub). - •Action: Check if the file exists using your file tools.
- •If no key is found:
- •Ask the user if they want to generate one.
- •If yes, use
run_shell_commandto generate it:ssh-keygen -t ed25519 -f "$env:USERPROFILE\.ssh\id_ed25519" -N ""(Note: This creates a key with NO passphrase for convenience. Ask the user if they prefer a passphrase).
- •Look for SSH keys in the user's
- •
Get Remote Details:
- •Ask the user for the
usernameandhostname(or IP) of the remote server. - •Ask for the
port(default is 22).
- •Ask the user for the
- •
Deploy Public Key:
- •To copy the key, you need to append the local public key content to the remote
~/.ssh/authorized_keysfile. - •Method A (PowerShell Script):
- •Use the bundled script
scripts/deploy_key.ps1. - •Command:
powershell -ExecutionPolicy Bypass -File "scripts/deploy_key.ps1" -User <username> -HostName <hostname> -Port <port> -PubFile <path_to_pub_key>
- •Use the bundled script
- •Method B (Manual Command Construction):
- •If the script fails or you prefer to show the user the command:
- •Construct the command:
Get-Content <pub_key_path> | ssh <user>@<host> "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys" - •Important: This step will require the user's password for the remote server. The
sshcommand will prompt for it.
- •Action: Run the command. If it hangs waiting for input (password), you may need to instruct the user to run it themselves in their terminal.
- •To copy the key, you need to append the local public key content to the remote
- •
Verify:
- •Ask the user to verify login by running:
ssh <user>@<host>
- •Ask the user to verify login by running: