How to create an SSH key in your PC & Mac
What is an SSH key?
An SSH key is simply an authentication method that can be used to gain access to a connection that is encrypted between two systems.
Instead of connecting to a system with a standard password and username that are difficult to memorize and vulnerable to theft, system administrators generally use a secure SSH key to log in to their targeted computers. The key replaces user identification, enabling the admin to login into the server using the key.
Once you interact via SSH, you will enter a shell session, through which you may connect with the server. Any commands you type into the local terminal in an SSH connection are passed through a secured SSH tunnel and executed on the server.
Use of SSH Keys
SSH keys are a critical security precaution for companies that want to interact and administer systems safely. Because the SSH protocol is extensively adopted in many computer-dependent services and:
Most businesses utilize SSH keys to verify identification and secure services from unauthorized usage or harmful assaults.
Generating an SSH key
An SSH key is composed of 2 keys, a private and a public key, which are combined to form a key pair that serves as the secure access credential.
To guarantee that these credentials are preserved safely, they are often handled by a company’s IT staff or with the assistance of a trustworthy Certificate Authority (CA).
Generating SSH key in PC
To create an SSH key pair on your PC, open the command prompt/windows terminal and type:
ssh-keygen
It will create public and private rsa key pairs and ask where to generate these files.
If you want the default location, you need to press enter. It will store the keys in the hidden .ssh directory. The SSH server can automatically locate the keys if the default directory is chosen.
To protect your private key, you need to provide a passphrase/password of any length. Every time you use the private key, you will have to input a passphrase for security.
You can simply press Enter if you don’t need a passphrase. However, any person who gains access to your private key can access your servers.
After pressing enter, this is shown:
The whole process generated two keys:
- id_rsa.pub, which can be shared with anyone.
- id_rsa, which should not be shared with anyone.
Generating SSH key in Mac
The process of generating the SSH key in the MacOS is very similar to generating it on your PC. But in Mac, an SSH key is generated by the terminal app. It provides a command-line text-based interface to the MacOS Unix shell.
- The first step for creating an SSH key is to open the terminal. For that open utilities from the application folder. It will have the terminal application.
- Next, you need to write ssh-keygen and press enter. If you want to use any other encryption type, you can type ssh-keygen -t dsa or ssh-keygen -t rsa, etc.
- A key pair is generated and after that, the prompt will need the directory. If you want to save the keys in the default directory (shown in brackets), you need to press Enter.
- Then, you need to enter a password or passphrase. You can leave it blank if you don’t want a password but it is recommended to type a passphrase for the encryption of the private key.
- After entering a passphrase, the key pair is generated and it shows:
Your identification has been saved in /root_directory/.ssh/id_rsa
Your public key has been saved in /root_directory/myname/.ssh/id_rsa.pub
Viewing Keys
To view the private key in visual studio, you can type the command:
root_directoty> cd..
root_directoty code .\.ssh\id_rsa
To view the public key type:
root_directoty code .\.ssh\id_rsa.pub
Changing passphrase or deleting the keys:
Many WordPress developers change the SSH key, its passphrase, FTP accounts, and all other passwords after some time to keep the websites maintained.
If you want to delete or change the passphrase of your SSH key:
Open the command window or terminal and type:
\ssh-keygen -p
Then the prompt will ask for the file location, where the key is stored.
After entering the location, you will have to enter the old passphrase. Then, you can set your new passphrase or simply press Enter if you want to remove it.
If you want to delete the SSH key pair, open the terminal and type:
rm -r.\.ssh
Connecting with SSH
After generating your SSH key, ensure that you copy the public key to your remote server, Mac, or PC. It connects with the private key, which allows your SSH client to make safe SSH interactions with no need for a conventional passphrase.
That’s all. I hope it helps you to create SSH key in your Windows or Mac. Please check out our Blog page to learn more about the WordPress. Drop a comment if you have anything to share 🙂