Key Facts
- SSH or Secure Shell is an encryption protocol for sending and receiving data securely by pairing a public key with a private match.If you want to connect to a remote server or add security to a hosting platform, you may need to generate an SSH key manually.RSA 2048-bit encryption is the most common type of SSH key. It is impressively secure compared to a standard password.
Although most computer users have probably not heard about SSH Keys, people in the IT space have probably heard it a lot. Especially with the rise of cloud computing. Over the last couple of years, internet security has become a significant need for a lot of us. SSH or Secure Shell is an encryption protocol to send and receive data securely by pairing a public key with a private match.
Most of the time, you do not need to generate an SSH Key manually, but there are a couple of reasons why you would need to. For example, if you are trying to connect to a remote server or add security to a hosting platform. Luckily for Mac users, you can generate SSH Keys or pairs using the terminal program. Before we get to that, though, let’s go through the history and use cases of SSH.
History of SSH
The very first version of the SSH protocol was introduced in 1995 by Tatu Ylonen. This protocol was created more out of need than a luxury. Ylonen was working at the University of Helsinki when they started to experience a sniffing attack on the university’s network. You might hear the term sniffing attack and not first think of a tech problem. A sniffing attack intercepts and logs the traffic on a network and can provide attackers with usernames and passwords, which can then be used to gain access to critical IT assets.
Because of this attack, thousands of credentials were affected, and by solving the problem, Ylonen developed an early version of the SSH protocol. Nowadays, SSH is widely used for logging into remote systems. If you have used a VPN or signed into a work computer from home, there is a good chance you have used SSH before. Its strong encryption makes it ideal for issuing remote commands and performing tasks remotely.
The most common type of SSH key is called RSA 2048-bit encryption, which, compared to the strength of a standard password, is incredibly secure. For a traditional password to be the same level of strength, it would need to contain 617 characters. SSH Keys always come in pairs, one public and one private. There are three different ways to refer to these pairs, user keys, host keys, and session keys. If both keys remain with the user, then they are user keys. Host Keys mean that both remain with the remote system. Finally, session keys are typically used when a large amount of data is being transmitted. Session keys are used to encrypt this information.
Alright, enough about how cool SSH is. Let’s learn how to generate an SSH Key on your Mac.
Steps To Generating an SSH Key
1. Open Terminal
The terminal might be an app that not a lot of Mac users have used before, so it might not be easy to find. The method we recommend using is hitting Cmd+Space at the same time and then typing in Terminal.
With the terminal open, we can start entering the commands. Note that this process will not have a visual UI like you might be used to with other Mac programs. It is just going to be command prompts.
2. Enter SSH-Keygen
When you open Terminal, it will have two lines filled out at first. We will start entering our commands on the second line. The first command we are going to enter is ssh-keygen, then press enter on your keyboard.
ssh-keygen
3. Select a Location
We highly recommend not changing the save locations or names because, with the defaults, your SSH client can automatically find and use your SSH keys when you are authenticating. To just accept the defaults hit enter on your keyboard.
Generating public/private rsa key pair. Enter file in which to save the key (/home/marc/.ssh/id_rsa):
4. (Optional) Overwrite Previous SSH Keys
If you have generated any SSH keys in the past, you will now be asked if you want to overwrite the previous key. To overwrite the previous SSH key, type in Y, and press enter. If you want to add a second SSH key, you can add a clarifying name instead of id_rsa. For example, github_rsa.
/home/marc/.ssh/id_rsa already exists. Overwrite (y/n)?
5. (Optional) Set a Password
If you want to add an extra layer of security, you can add a passphrase. The command prompt will now allow you to create a passphrase if you want to. Type in your password where it says Enter passphrase (empty for no passphrase): and then enter the same passphrase on the line below to confirm it. Then press enter.
We do recommend creating a password, but if you do not want to simply just press enter here to continue.
Created directory ‘/home/mar c/.ssh’. Enter passphrase (empty for no passphrase): Enter same passphrase again:
6. Generate SSH Key
Whether you chose to create a password for your SSH Key or not, after pressing enter, your key will be generated.
Your identification has been saved in /home/marc/.ssh/id_rsa. Your public key has been saved in /home/marc/.ssh/id_rsa.pub. The key fingerprint is: a9:49:EX:AM:PL:E3:3e:a9:de:4e:77:11:58:b6:90:26 marc@203.0.113.0 The key’s randomart image is: +–[ RSA 2048]—-+ | ..o | | E o= . | | o. o | | .. | | ..S | | o o. | | =o.+. | |. =++.. | |o=++. | +—————–+
Conclusion
Congratulations, you have now successfully created an SSH Key. You can use these to connect to remote servers, issue remote commands, or whatever specific reason you probably came to this article for. Remember that when you create an SSH key, most services require you to create one public and one private key. You will only have access to the private key, but the server admins will have access to your public key to identify you.
This tutorial focused on just creating RSA keys which are the most common. But if you want to learn more about the other types of SSH keys, be sure to keep an eye out for more complex dives into SSH Key variants.
Up Next…
- Edge vs Chrome: Full Comparison: Both browsers are inspired by the same open source browser. However, one of them has more customizable options compared to the other. Which of them wins out in the end? Discover the answer here.What Are ‘Data Brokers’ and Are They Evil? Your personal information is an invaluable asset to these companies which sell them for a profit. Do they have the right to do so? Find out here.How to See All Your Google Activity And Delete It Forever: Although large tech companies seem to be able to peer into everyone’s private lives, you have a measure of control. Find out how to exert it here.