How can i enable SSH to my linux host using ssh key?

Enabling SSH with key authentication involves generating an SSH key pair and configuring your SSH server to allow key-based authentication. Here are the basic steps:

 

  1. Generate an SSH key pair

On your local machine, generate an SSH key pair using the following command:

 

ssh-keygen -t rsa

This will create a public key file (typically named id_rsa.pub) and a private key file (typically named id_rsa) in the .ssh directory in your home directory.

 

  1. Copy the public key to the server

Copy the contents of the public key file to the server where you want to enable SSH key authentication. You can do this manually by copying and pasting the contents of the file, or you can use the following command:

 

ssh-copy-id username@server

This will copy the public key to the server and add it to the authorized keys file.

 

  1. Configure the SSH server

On the server, open the SSH server configuration file (/etc/ssh/sshd_config) and ensure that the following options are set:

 

PubkeyAuthentication yes

AuthorizedKeysFile .ssh/authorized_keys

Save the changes to the configuration file and restart the SSH server.

 

  1. Test the SSH connection.

Test the SSH connection to the server by attempting to connect using the private key file:

 

ssh -i ~/.ssh/id_rsa username@server

If the key-based authentication is successful, you should be able to connect to the server without entering a password.

 

Note: Be sure to keep the private key file secure and do not share it with anyone. Anyone with access to the private key file can potentially gain access to your server.

 

 

  • Linux, ssh, administation
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

how can I make sure the security is hardened for my Linux Server?

Security hardening is an important part of maintaining a secure Linux operating system. Here are...

How to install and configure Firewalld in linux?

Firewalld is a firewall management tool that comes pre-installed on many Linux distributions....

How to install Ioncube loader on CentOS, Debian and Ubuntu

  Introduction Using ionCube encoded and secured PHP files requires a file called the...

How to enable Root account within Ubuntu Server

Software Requirements and Conventions Used Software Requirements and Linux Command Line...

Error: 413 Request Entity Too Large

? Error: 413 Request Entity Too Large Overview The “413 Request Entity Too Large” error occurs...