Simplifying SSH Key Management

For the longest time, anytime I wanted to create SSH keys on my local machine and publish them on a server, I'd go through this manual process.

Step 1 - Create an SSH Key

This command creates a public key ( and a private key (id_rsa) in the ~/.ssh/ directory.


Step 2 - Manually Copy to Remote Server

After generating the keys, I'd log into the remote server and manually copy the keys using the following commands:

# Double-check authorized keys
nano ~/.ssh/authorized_keys

# Create an SSH key

# Copy private key to your local computer
cp .ssh/id_rsa > /path/to/local/computer

# Remove private key from the current location
rm -rf .ssh/id_rsa

# View the public key
nano .ssh/

# Remove the public key file
rm -rf .ssh/

# Paste the public key into authorized keys
nano ~/.ssh/authorized_keys

New Way - Using ssh-copy-id

Now, there's a more straightforward way to copy your public key to the authorized_keys file on the remote server. Simply use ssh-copy-id:

# Generate SSH Key (if not done already)

# Copy Public Key to Remote Server
ssh-copy-id user@remote_server

This streamlined approach eliminates the manual steps of copying and pasting keys, making the process more efficient and user-friendly.