Sunday, May 4, 2025
HomeDevOpsHow to set up SSH public key authentication to connect to a...

How to set up SSH public key authentication to connect to a remote system?

Create a ~/.ssh/config and open it in the editor. Write like following

Host remote_server
    Hostname [remote server name or IP address or DNS name]
    User [remote username]
    Port [port number]
    IdentityFile [local path to private key file]

Replace [remote server name or IP address] with the actual name or IP address of the remote system, [remote username] with the actual username on the remote system, and [local path to private key file] with the actual path to the private key file on your local system, and [Port] with your server’s ssh port number, you can find it from security groups in EC2 dashboard (sidebar). Save the file and close the editor.

Now, you will need to write protected the .pem file. To do that run the following command on your terminal.

chmod 400 my_production_server.pem

Open the terminal and type ssh remote_server. If your configuration is correct then it will connect the server.

Example for AWS EC2 instance connection through key pair:

Host my_production_server
    Hostname 12.567.0.1 #this is not valid IP
    User root
    Port 22
    IdentityFile /home/user/app/keys/my_production_server.pem
Atiq
Atiqhttps://elearn.softscholar.com
Software Engineer with extensive experience developing modern web applications using various programming languages and frameworks. Strong background in converting legacy systems to modern architectures and contributing to SaaS platforms. Proficient in working with microservices and cloud technologies. Adept at managing teams, implementing CI/CD pipelines, and deploying SaaS platforms to optimize enterprise operations. Proven ability to lead cross-functional teams and mentor junior developers, ensuring project success and team growth.
RELATED ARTICLES

1 COMMENT

Leave a Reply to Abdullah Sarkar Cancel reply

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments