I have been working with authenticating a server with permission file (ssh). What I’ve learned so far covers only the surface. Here’s a short summary of my understanding.
You need to start by configuring the public key in the server where the server allows access when the user presents a valid private key. Following are the procedures I followed:
- Secure Shell (SSH) is used everywhere for managing servers and devices.
- Instead of insecure username and password, ssh uses secure key or SSH key pair(private and public).
Generating SSH key
The above code generates ssh key pair (private and public). If you do not specify any name for the key name, id_rsa will be generated as default: Private File: id_rsa Public File: id_rsa.pub
Adding SSH key
We need to add ssh key in order to use while connecting to any remote server.
Connecting to remote server
Configuring server for your private key to work
You may need password to add the public key to the under the file ‘authorized_keys’ list for linux servers. This file is located at ~/.ssh/ folder.
You can manually add the key to authorized_keys file. For that, copy the public_key content from id_rsa.pub and paste it into new line in authorized_keys. To copy the key from command line:
- Connect to the server using normal ssh command with password.
- Go to home folder
- Create folder .ssh
- create file authorized_keys
- use vi to edit the authorized_key files -> vi authorized_keys
- paste the public key content here
You can use special command to copy the public key to a linux server
This will add the public key directly to authorized_keys file. If the file is not created, it will create it automatically