Tuesday, 2 April 2019

SSH Connection using SSH Key Pair

We can access a remote machine using ssh connection  without a password by using ssh key pair.

Generate a key pair and place a public key on a remote machine and private key on your local machine.

Use the following commands to generate the key pair and configure ssh connections.

1. Go to .ssh folder and make sure there is no existing key files.

2. Generate the key

     ssh-keygen -t rsa -C "sample_email@sample.com"

3. Provide the password for key.

4. Two files will be generated.
   id_rsa  --> Private Key
   id_rsa.pub --> Public Key

Note: Dont share private key with anyone. Public key can be shared with remote users.


5. Copy the public key using cat command.

cat ~/.ssh/id_rsa.pub


6.  Pass the public key to the remote server user and ask them to add it to authorized key file.

~/.ssh/authorized_keys

echo public_key_string >> ~/.ssh/authorized_keys

or  use the following command if the folder and authorize_keys file is missing

cat ~/.ssh/id_rsa.pub | ssh your_user@your_server_ip "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"


use VI command to add the key to the file with comments.

To add key automatically
ssh-copy-id -i ~/.ssh/id_rsa.pub your_user@your_server_ip
 


7.  Try connecting using ssh command from local machine.

ssh -i private_key_file user_name@host_name.


===========================================

We can generate SSH key using Putty Gen

  •  Open Putty Gen
  • Select  RSA as an algorithm.
  • Select Generate Key Pair
  • Now move the mouse Key Generate window.
  • It will generate 
  • Copy the Key and save it as a .pub - public file. 
  • Select Save Private Key Option to save .ppk file. 
  • Now you can generate SSH key by selecting conversions tab and then export OpenSSH Key option. 
  • Save the file as .ssh file.




No comments:

Post a Comment

ERP - GL - Chart Of Accounts

Segments in General Ledger   Segments  are dimensions used to represent an account in a financial system. A company can have anywhere from...