Setting up SSH keys to a Ubuntu Server with Mac

people

Dev

. 1 min read

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

Dev
Dev.2 min read

Window Server 2025 Contabo VPS Install Guide

Window server in contabo is very costly but you can deploy your license key with custom image.

Dev
Dev.1 min read

Git/Github Clone Private Repository on Ubuntu Server 24.04

GitHub is a free platform that provides repository hosting and We will guide you to install Git on Ubuntu 24.04, adding and cloning a repository from GitHub to your Ubuntu VPS server.

.
Dev
Dev.1 min read

RAID 1 setup on Hetzner Dedicated Server - Rescue Ubuntu Install EasyPanel

Installing Ubuntu on Hetzner Server in Rescue Mode with RAID1 for Enhanced Storage Capacity. resizing MD2 and MD3, utilising full NVME in EasyPanel

.
Lets Try
Lets Try.1 min read

Deploy Tailscale in Portainer docker container Raspberry pi

A comprehensive guide on deploying Tailscale through Portainer in Raspberry pi. lets integrate Tailscale into your existing Docker setup.

Lets Try
Lets Try.1 min read

Nginx Proxy for s3 compatible storage & buckets

Nginx can be used as a reverse proxy for S3 compatible storage and buckets. This is useful in many scenarios, including adding authentication, security or custom routing to S3-compatible solutions. 

Built on Koows