SSH keys
SSH Keys
Purpose
Primarily used for authentication when connecting to remote servers via the Secure Shell (SSH) protocol. They allow for passwordless, secure logins.
Mechanism
An SSH key pair consists of a private key (kept secret on your local machine) and a public key (placed on the remote server). When you attempt to connect, the server challenges your client, and your client uses the private key to prove its identity without sending the private key itself.
Usage
Logging into servers, secure file transfers (SCP, SFTP), and Git operations with SSH URLs.
Check to see if there are existing ssh keys in your computer
In Windows,
- Open Git Bash.
- Enter ls -al ~/.ssh to see if existing SSH keys are present.
Lists the files in your .ssh directory, if they exist$ ls -al ~/.ssh
Generate new ssh keys
(When you’re prompted to Enter a file in which to save the key, press Enter. This accepts the default file location.) Now add this SSH ket to bitbucket server.
Files with names other than id_rsa may not be automatically picked up by the ssh agent in your computer.
Adding new ssh keys to ssh-agent
If you want to add an SSH key generated from Git console to the ssh-agent in your computer :
You might need to start ssh-agent before you run the ssh-add command:
eval `ssh-agent -s`
or
eval $(ssh-agent)
If the eval commands don’t work (in Windows computers)
- Open git bash
ssh-agent bash- and then execute:
ssh-add <path-to-your-private-key>
Add your SSH private key to the ssh-agent using the following command:
ssh-add ~/Downloads/CloudForgeGitSSHKeys/id_rsa
(this should point to the location of the private key file)
Error related to file permissions
If you see the follwing error,
Permissions 0664 for '/home/explorer436/.ssh/id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
fix the permissions by using these:
Keys need to be only readable by you: chmod 400 ~/.ssh/id_rsa
If Keys need to be read-writable by you: chmod 600 ~/.ssh/id_rsa
600 appears to be fine as well (in fact better in most cases, because you don’t need to change file permissions later to edit it).