How To Create SSH Keys with OpenSSH on macOS, Linux, or Windows Subsystem for Linux

Creating SSH keys with OpenSSH on macOS, Linux, or Windows Subsystem for Linux (WSL) involves a few simple steps. Here's a guide:

  1. Open Terminal (macOS/Linux) or WSL (Windows): Launch your terminal application or open the Windows Subsystem for Linux (WSL) terminal.
  2. Generate SSH Key Pair: Use the ssh-keygen command to generate your SSH key pair. The default options are usually sufficient, but you can customize them if needed.

                    
                        ssh-keygen -t rsa -b 4096 -C "[email protected]"
                    
                

    Replace "[email protected]" with your actual email address. You can also specify a different filename if desired.

  3. Follow Prompts: After running the command, you'll be prompted to choose the location to save the keys and optionally enter a passphrase. Press Enter to accept the default location or specify a different one. If you choose to set a passphrase, make sure to remember it as you'll need it to unlock your private key.
  4. Verify SSH Key Generation: Once the key pair is generated, you'll see output similar to this:

                    
                        Your identification has been saved in /home/username/.ssh/id_rsa.
                        Your public key has been saved in /home/username/.ssh/id_rsa.pub.                    
                    
                

  5. View Your Public Key: You can display your public key using the cat command and copy it to your clipboard

                    
                        cat ~/.ssh/id_rsa.pub
                    
                

  6. Add SSH Key to SSH Agent (Optional): If you've set a passphrase for your private key, you can add it to the SSH agent to avoid entering the passphrase every time you use your SSH key.

                    
                        ssh-add ~/.ssh/id_rsa
                    
                

  7. Use Your SSH Key: You can now use your SSH key pair to authenticate with remote servers. Paste your public key (id_rsa.pub) into the appropriate location on the server you want to connect to.

That's it! You've successfully created SSH keys with OpenSSH on macOS, Linux, or Windows Subsystem for Linux (WSL). You can now securely authenticate with remote servers using SSH.

Top 50+ Linux Commands

Linux is a powerful operating system with a rich set of commands that allow you to control nearly every aspect of the system. Here is a list of over 50 Linux commands that you should know, including some of the most important ones. beginning of what …

read more

How To Install Node.js on Rocky Linux 8

the process of installing Node.js on Rocky Linux 8 is similar to other Red Hat-based distributions. Please note that there might be updates or changes, so it's a good idea to check the official documentation for the latest information. Here's a gener …

read more