Blog
How to Connect the Remote Server Using SSH on a Mac
An SSH is a protocol through which you can access your cloud server and execute shell commands.
You can operate SSH Key to specify authorized computers without the need for passwords and to interact with your servers.
SSH is encrypted with Secure Sockets Layer (SSL), which makes it difficult for these communications to be intercepted and read.
This article provides steps for connecting to a remote server from a computer running Mac Operating System by using Secure Shell (SSH). It even discusses generating an SSH Key and adding a public key to the remote server.
What Is Remote Access Server
A server that is dedicated to managing users that are not on a LAN but require remote access to it. The remote access server permits users to achieve access to files and print services on the LAN from a remote location.
For example, a user who dials into a network from home operating an analog modem or an ISDN connection will dial into a remote access server.
Once the user is authenticated he can access shared drives and printers as if he were physically attached to the office LAN.
Concept of an SSH Key
SSH key is used to attach a client to a server. It is interesting since it avoids having to enter a password every time we want to access a specific server.
SSH keys come in multiple sizes, but a popular choice is an RSA 2048-bit encryption, which is a 617 digit long password.
On Windows systems, it is possible to generate your own SSH key pair by downloading and operating an SSH client like PuTTY.
On Mac & Linux systems, it is probable to generate an SSH key pair using a terminal window. Observe the video below to find out how to generate your own RSA key pair on Mac and Linux.
Way to Connect Remote Server Using SSH on Mac
You can secure SSH access to your cloud server against brute force password attacks by operating a public-private key pair.
A public key is positioned on the server and a matching private key is placed on your local computer. If you configure SSH on your server to get only connections operating keys, then no one can log in by using just a password.
Connecting customers are needed to operate a private key that contains a public key registered on the server. For more on safety, review Linux server protection best practices.
Using the Following Step to Generate an SSH Key Pair -
Step 1 - Execute the following command using your email address as a label. Substitute your email address for your_email@example.com in the command. ssh-keygen -t RSA -C "your_email@example.com"
A message indicates that your public-private RSA key pair is being generated. At the fast, press Enter to use the default location or enter a file in which to save the key and press Enter.
Step 2 - If you want the additional security of a password for the key pair, enter a passphrase and press Enter. If you do not want to utilize a password with the key pair, press Enter to continue without setting one.
Your key pair is generated, and the output looks similar to the following example -
Your identification has been saved in /LocalFileLocation/id_rsa. Your public key has been saved in /LocalFileLocation/id_rsa.pub. The key fingerprint is: 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
Step 3 - Optionally, add your new key to the local ssh-agent file to help SSH to find your key without the necessity to specify its place every moment that you connect
ssh-add ~/.ssh/id_rsa
You can use an SSH composition shortcut instead of the ssh-agent file by following the instructions in the Shortcut configuration section later in this article.
Add the Public Key to a Cloud Account
To assemble it easy to add your key to new cloud servers that you make, upload the public key to your cloud account by following these steps
Step 1 - Log in to the Cloud Control Panel.
Step 2 - In the highest navigation bar, click Select a Product > Rackspace Cloud.
Step 3 - Choose Servers > SSH Keys.
Step 4 - Press Add Public Key.
Step 5 - Enter a key name, such as Work Laptop, to remind you which computer this key is for.
Step 6 - Choose the region for which you want to store the public key. To store your key in numerous regions, repeat these stages for each region. The key must reside in the exact region of the server.
Step 7 - Paste the contents of the id_rsa.pub file that you assembled into the Public Key field. You can get the file contents by either beginning the file in a text editor or by executing the following command [ cat ~/.ssh/id_rsa.pub ]
Step 8 - Press Add Public Key. If you want to add the key manually, instead of by operating the Control Panel, review Linux server security best practices and use the following command -
ssh-copy-id -i ~/.ssh/id_rsa.pub {username}@{remotePublicIPAddress} baki
Create a New Server by Using a Stored Key
When you create a new cloud server, you can add a reserved key to the new server.
On the Create Server page, extend the Advanced Options section.
From the SSH Key menu, choose your key from the list.
If you don’t see a reserved key in the list, you can perform one of the following actions -
Change the region for the latest server to the region where you have stored the SSH key.
Repeat the steps in the preceding section, Add the public key to your cloud account, to add the key to the region in which you want to assemble the new server.
Add the Key to an Existing Server
You can not use the Cloud Control Panel to add a public key to an existing server. Observe these steps to add the key manually -
On your cloud server, assemble a directory named .ssh in the home folder of the user that you attach to by using SSH. mkdir -p ~/.ssh
Create or edit the authorized_keys file and add your public key to the list of authorized keys by utilizing the following command -
nano ~/.ssh/authorized_keys
A key is all on one line, so confirm that the key isn’t broken by line breaks. You can contain numerous keys in the authorized_keys file, with one key per line.
Set the proper permissions on the key by utilizing the following commands-
chmod 700 ~/.
ssh chmod 600 ~/.ssh/authorized_keys
If you have any issues and need to fix permissions issues, run the following command -
restorecon -R -v /root/.ssh
After you have added the public key to the authorized_keys, you can create an SSH connection by using your key pair instead of the account password.
Shortcut Configuration (Optional)
Use the next instructions to set up a connection shortcut by assembling a ~/.ssh/config file on your local computer and adding your server and key details to it.
Using a text editor, add the following text to the ~/.ssh/config file, changing the values to match your server information -
Host shortcutName
HostName serverAddressOrIPAddress
User remoteUsername
IdentityFile /path/to/appropriate/ssh/rsa/private/key
Each of the following entries represents a feature of the server -
Host - A shortcut name that you operate to tell SSH to use this connection.
HostName - The address of the server to which you connect.
User - The name of the user account to attach to the server.
IdentityFile - The location of the private key file (id_rsa).
After you set up the config file, attach it to the server by utilizing the following command with your shortcut name -
[ ssh shortcutName ]
Conclusion
In the above article, we will give information about how to connect the remote server using SSH on Mac. The SSH is the key to creating private and public keys. If you have any doubts about connecting to a remote server using the SSH key then let me know in the comment box.