SSH keys provide a secure, convenient way to authenticate with servers without needing passwords. Here’s how you can easily create an SSH key pair on your Ubuntu system.
Best Practice: Check for Existing SSH Keys
Before creating a new SSH key pair, it’s recommended to verify if you already have one. Run the following command:
ls -al ~/.ssh
If you see files named id_rsa and id_rsa.pub, you already have an SSH key pair.
Step 1: Generate a New SSH Key Pair
If you don’t have existing keys, or you want to create a new pair, use the following command:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Replace your_email@example.com with your actual email address for identification purposes.
You’ll be prompted to specify where to save the key. Press Enter to accept the default location. You’ll then be asked to create a secure passphrase. This is optional but strongly recommended for security.
Step 2: Add Your SSH Key to the SSH Agent
To use your key easily, add it to the SSH agent with the following commands:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa
Step 3: Copy the Public Key to Your Server
Now, copy your public key to your remote server:
ssh-copy-id username@your_server_ip
Replace username and your_server_ip with your actual server username and IP address.
After running this command, you’ll be prompted to enter your server password. Once complete, you’ll be able to securely log in to your server without needing a password.
Step 4: Test Your SSH Connection
Finally, test your SSH key authentication by logging into your server:
ssh username@your_server_ip
If everything is set up correctly, you’ll log in securely without entering a password!
You’re now set up with SSH key-based authentication on Ubuntu, enhancing your security and workflow efficiency!

Comments