Generating SSH keys on a Mac for use with an Ubuntu server is a straightforward process. Here’s a step-by-step guide:
On your Mac, open the Terminal application. You can find it in the Applications folder under Utilities, or you can search for it using Spotlight.
Use the ssh-keygen
command to generate a new SSH key pair. Run the following command:
ssh-keygen -t rsa -b 4096 -C "your_email@domain.com"
-t rsa
: Specifies the type of key to create, which is RSA in this case.
-b 4096
: Specifies the number of bits in the key, which is 4096 bits.
-C "your_email@domain.com"
: Provides a comment, typically your email address.
After running the command, you’ll be prompted to specify a location for the key files. By default, it will save the keys in the ~/.ssh
directory:
Enter file in which to save the key (/Users/yourusername/.ssh/id_rsa):
You can press Enter to accept the default location, or you can specify a different path if you prefer.
Next, you’ll be prompted to enter a passphrase for your key. This passphrase adds an extra layer of security. Enter a passphrase or press Enter for no passphrase:
Enter passphrase (empty for no passphrase): Enter same passphrase again:
You need to copy the public key to your Ubuntu server. The public key file will be named
cd ..
cd /root/.ssh
nano authorized_keys
authorized_keys
. Ensure that the permissions on your Ubuntu server are set correctly:
ssh username@your_ubuntu_server_ip chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
Finally, test your SSH connection:
ssh -i id_rsa root@10.10.10.10
id_rsa
: Specifies the name of your private key,
You should be able to connect without being prompted for a password.
By following these steps, you should have successfully generated SSH keys on your Mac and set them up for secure access to your Ubuntu server. If you encounter any issues or need further assistance, feel free to ask!