HOWTO- Generate SSH Key
Generate SSH Key Pair:
Type the following command to generate an SSH key pair. The
-toption specifies the type of key to create (in this case, RSA), and the-boption specifies the number of bits in the key (2048 is a common choice).
ssh-keygen -t rsa -b 2048
- Press Enter. It will prompt you for a location to save the key. The default location is usually fine, so just press Enter.
- It will also ask you to enter a passphrase. This is an additional layer of security. You can enter a passphrase or leave it blank, but using a passphrase is recommended for better security.
Locate Your SSH Key:
- By default, the keys are stored in the
~/.ssh/directory. Your private key will be namedid_rsaand your public key will be namedid_rsa.pub.
- By default, the keys are stored in the
Display Your Public Key: You can view your public key using the following command:
cat ~/.ssh/id_rsa.pub
Copy the output.Add the Public Key to the Remote Server:
Log in to your remote server.
Navigate to the
~/.ssh/directory (create it if it doesn't exist).Open or create a file named
authorized_keys(or append to an existing one) and paste the contents of your public key into this file.echo "your_public_key_here" >> ~/.ssh/authorized_keys
Make sure to replace "your_public_key_here" with the actual public key you copied.Secure Your Private Key:
Ensure that your private key (
id_rsa) is only readable by you:chmod 600 ~/.ssh/id_rsa
Now you should be able to SSH into your remote server using the private key. When connecting, the SSH client will use your private key for authentication.
Comments
Post a Comment