Using RSA keys for working with remote repos
This is a secure way to work with systems supporting the work with RSA key pairs to establish secure connection.
Generate RSA key pair
Check if any keys are already here
ls -l ~/.ssh | grep id_rsaIf nothing found, then create new
Create new private / public key pair
ssh-keygen -t rsa -b 4096 -C cheshi.mantu@emailserver.server-C cheshi.mantu@emailserver.server is generally a comment to the key pair, it allows you to quickly recognise the purpose of your key
The passphrase must not be empty. The passphrase must not be simple, do not use 1234567890 or “password” or anything equally ridiculous words, otherwise the key pair can be easily compromised and a rogue actor will be able to make some actions as if it you and this could be nasty. You have to be very careful especially with production systems and using an unprotected RSA key pair. Think thrice.
Check if keys are generated
ls -l ~/.ssh | grep id_rsaSet correct permissions to RSA files
chmod 644 id_rsa.pubchmod 600 id_rsaSecret key must be 600: With this, you are giving read and write permission to the owner user. Group members and others cannot read, write or execute. Even the owner cannot execute the file with this permission set.
Public key must be 644: The owner can read and write but cannot execute it. Group members and others can read the file but cannot write or execute it.
Provide public key to a remote system
cat ~/.ssh/id_rsa.pubthe output is to be copied fully to a remote system.
Use an RSA key pair in the scope of current user session
If you won't do this, then the ssh agent will always ask you to provide the password for the RSA secret key (you've protected it with the passphrase, right?). If you are sure your computer won't be accessed by anyone else, then execute this command:
ssh-addor specify which key to add to the agent's session
ssh-add ~/.ssh/id_rsaEnter your password and you'll be able to work in scope of current user session without entering the passphrase.
Checking if ssh agent is running
eval $(ssh-agent -s)Updating the comment of an existing key
ssh-keygen -c -f ~/.ssh/id_rsa -C "new_comment"