How to create passwordless access

From PKC
Revision as of 04:55, 28 February 2022 by Emhavis (talk | contribs) (→‎Introduction)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

This is the reference page to create passwordless access to your linux server. The method is a more convinience and secure method to access and perform various administration and/or configuration task on your server. However, there are several rules to comply in order to enhance your server security. For further reading, please look through Public Key Authentication article.[1]

Steps to install passwordless access

First, execute ssh-keygen on your terminal

$ ssh-keygen

This is an interactive command-line-interface to generate public/private keypair, please follow the instruction and store the key file into your chosen directory folder to use it later on. Once its finished, next step is to register your public key into target server. Please also be aware that you will need working user and password beforehand. Type in below command to register

$ ssh-copy-id -i [your-public-key-file] [user]@[server-name or IP]
example
$ ssh-copy-id -i ~/.ssh/id_rsa.pub manageuser@23.122.64.23

Then, the process will ask your password of user [manageuser] and installed the public key into target server. To ensure the public key is installed correctly, please execute below command

$ ssh -i [your-private-key] [user]@[server-name or IP]

if it is successfully connected without asking password, that is the installation has been correctly done.

Further Automation

To further automate the login process, you can register the private ke into ~/.ssh/config file, below are the sample entry in config file to enable local naming resoluton.

Host [your-chosen-hostname]                         
 HostName [actual server host/IP]                  
 IdentityFile [path-to-your-identity file]
 User [user]

By entering the lines into config file, you can call the server by using [your-chosen-hostname], and the shell will automatically resolve all the necessary configuration to connect.

References

Related Pages