Ssh Linux
This configuration starts by creating a pair of keys and handling them on linux.
This is good also for tasks like connecting to a remote machine in the cloud.
At the end, we also go through using this for github (so adding the public key to a github account).
Add SSH key
- To work with github or connecting to a remote server we normally need to use SSH keys.
- We start by creating a pair of keys, as in the following example:
1ssh-keygen -t ed25519 -C "yuval.shaul@gmail.com"
- The email address at the end is just a comment you attach to the public key.
- -t ed25519 is the key type
- The response:
1Generating public/private ed25519 key pair.
- Now I can change the key name if I wish (I leave this blank to use the default name)
1Enter file in which to save the key (/home/yuval/.ssh/id_ed25519):
- I left everything else empty
- To verify:
1**ls ~/.ssh**
Make the key read only
If I skip this step - my key will not work.
1yuval@comp> chmod 400 id_ed25519
2yuval@comp> ls -l id_ed25519
3-r-------- 1 yuval yuval 411 Nov 3 18:37 id_ed25519
4yuval@comp>
Add keys to the ssh agent
You can read about the ssh agent here.
1# First command to run the ssh agent
2eval "$(ssh-agent -s)"
3# Next command to add a key to the agent (my key is called id_ed25519, and it is on ~/.ssh directory)
4ssh-add ~/.ssh/id_ed25519
Add the public key to github
Add the public key to github like this:
- Cat the public key:
1cat ~/.ssh/id_ed25519.pub
- Copy with your mouse
- Go to your account settings (top-right-settings)
- Click SSH and GPG keys.
- Click New SSH key.
- In the "Title" field, add a descriptive label for the new key.
- Select the type of key (authentication in out case)
- In the "Key" field, paste your public key (including the email part)
- Click Add SSH key.