Setting up SSH keys to a Ubuntu Server with Mac

author

Dev

. 1 min read

Follow

Generating SSH keys on a Mac for use with an Ubuntu server is a straightforward process. Here’s a step-by-step guide:

Step 1: Open Terminal

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.

Step 2: Generate the SSH Key Pair

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.


Step 3: Specify the Key File Location

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.

Step 4: Set a Passphrase

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:


Step 5: Copy the SSH Key to the Ubuntu Server

You need to copy the public key to your Ubuntu server. The public key file will be named

  • Login to Server : ssh root@10.10.10.10 (your Server IP)
  • After login Type command : cd ..
  • then Type : cd /root/.ssh
  • Edit the file : nano authorized_keys
  • Paste your public key which created earlier ( id_rsa.pub ) Your public key will look like this after pasting in authorized_keys .

  • You can Add multiple Public keys in this file. in above image per public keys shows in per line.
  • Save the file Ctrl X and YES

Step 6: Set Permissions on the Ubuntu Server

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

Step 7: Test the SSH Connection

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!


More Stories from Developerbook

How to setup Erlang on windows environment

How to setup Erlang on windows environment

How to configure eclipse plug-in for erlang

How to configure eclipse plug-in for erlang

Isolation concept for transaction

Isolation concept for transaction

Alloy ui basic tutorial

Alloy ui basic tutorial

First web service using eclipse and java

First web service using eclipse and java