Search Our Database
How to generate your SSH Public key
Introduction
Secure communication between your local machine and a remote server is crucial, especially when dealing with sensitive data. One of the most widely used methods to establish a secure connection is through SSH (Secure Shell) keys. SSH keys consist of a key pair — a public key and a private key. The private key remains on your local machine and must be kept secure, while the public key is shared with the remote server or any other individual who needs access.
Generating an SSH public key involves first creating a private key. The public key is then derived from the private key, and can be shared with others to allow access to the server without needing a password. This enhances security, as private key-based authentication is far more secure than password-based methods.
This guide will walk you through the steps to generate both your private and public SSH keys using a Linux-based system or any system that supports SSH. Once generated, the public key can be shared with anyone who needs access to your server, while the private key stays secure on your local machine.
By the end of this guide, you will have a functioning SSH key pair, and you’ll know how to share your public key to grant access to your server without compromising the security of your private key.
Step-by-Step Guide
Step 1: SSH into the server with root privileges
- Start by accessing your server via SSH using root or sudo privileges:
ssh root@your_server_ip
Step 2: Navigate to the .ssh directory
- Once you’re logged in, navigate to the .ssh directory to store the SSH keys:
cd ~/.ssh ls
You should see a file named known_hosts if this directory already exists.
Step 3: Generate the SSH key pair
- Now that you’re in the .ssh directory, use the following command to generate the key pair:
ssh-keygen
The system will prompt you with the following questions:
Generating public/private rsa key pair. Enter file in which to save the key (/Users/your_user/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/your_user/.ssh/id_rsa. Your public key has been saved in /Users/your_user/.ssh/id_rsa.pub.
Press ENTER at each prompt to proceed with the default options, unless you need a specific passphrase.
Step 4: Retrieve and share your public key
- After the key pair is generated, your private key will be saved as id_rsa, and your public key will be saved as id_rsa.pub.
- If someone requests your public key for access, you can view the content of your public key using the command below:
cat ~/.ssh/id_rsa.pub
The output will look something like this:
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAr+uQzkfH1xdTTDW7w3sdyGV3rTBHdfb2OaUFnF GPl+nafzlHDTYW7hdI4yZ5ew18JH4JW9jbhUFrviQzM7xlELEVf4h9lFX5QVkbPppSwg0cda3 Pbv7kOdJ/MTyBlWXFCR+HAo3FXRitBqxiX1nKhXpHAZsMciLq8V6RjsNAQwdsdMFvSlVK/7XA t3FaoJoAsncM1Q9x5+3V0Ww68/eIFmb1zuUFljQJKprrX88XypNDvjYNby6vw/Pb0rwert/En mZ+AW4OZPnTPI89ZPmVMLuayrD2cE86Z/il8b+gw3r3+1nKatmIkjn2so1d01QraTlMqVSsbx NrRFi9wrf+M7Q== your_user@your_host
Copy the contents of the id_rsa.pub file and send it to the person requesting access.
Conclusion
By following these steps, you have successfully generated your SSH key pair. The public key can now be shared with users who need to access your server, while your private key should remain secure. For additional assistance, please contact our support team at support@ipserverone.com.