PiotrRybka82
8/11/2019 - 8:35 AM

SSH Key

# list of all .ssh files in the directory
$ ls -al ~/.ssh

# default filenames of public keys: 
# id_dsa.pub
# id_ecdsa.pub
# id_ed25519.pub
# id_rsa.pub

# if there is no public/private key // you're received an error // you don't want to use an existing one -> generate_new_ssh_key.sh
# if you want to use an existing key -> add_ssh_key_to_shh_agent.sh
# create new ssh key with email as a label
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

# when prompted to "Enter a file in which to save the key," press Enter to accept the default file location
> Generating public/private rsa key pair.

# at the prompt, type a secure passphrase (see https://help.github.com/en/articles/working-with-ssh-key-passphrases)
> Enter passphrase (empty for no passphrase): #[Type a passphrase]
> Enter same passphrase again: #[Type passphrase again]
# before adding ssh key, check for existing keys and optionally create a new one
# ensure the ssh-agent is running (if using the Git Shell installed with GitHub Desktop, the ssh-agent should be running)
# to start the ssh-agent in the background manually: 
$ eval $(ssh-agent -s)
> Agent pid 59566

# add your SSH private key to the ssh-agent
# if the key has a different name // an existing key is added with a different name -> replace id_rsa in the command with the name of the key file
$ ssh-add ~/.ssh/id_rsa

#add new ssh key to GitHub account -> add_key_to_github_account.sh (https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account)
# copy the SSH key to your clipboard
$ clip < ~/.ssh/id_rsa.pub

#  if clip isn't working, locate the hidden .ssh folder, open the file in a text editor, copy it to the clipboard

# in the github account: 
# click profile photo -> click Settings -> click SSH and GPG keys -> click New SSH key // Add SSH key
# add a descriptive label for the new key, e.g. "Personal MacBook Air"
# paste the key into the "Key" field
# click Add SSH key
# if prompted, confirm your GitHub password
$ ssh -T git@github.com
# Attempts to ssh to GitHub

# 2 possible warnings: 
# 1st:
> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
> Are you sure you want to continue connecting (yes/no)?
# 2nd: 
> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?

# if the fingerprint in the message matches one of the messages above, type yes

# if the resulting message doesn't contain your username -> https://help.github.com/en/articles/error-permission-denied-publickey
> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.