Based on Github Doc, and clarified the confusing parts
-
Open Terminal
-
Checking for existing SSH keys
$ ls -al ~/.ssh # Lists the files in your .shh directory, if they exist # Make sure you don.t have `id_rsa_github` file # Otherwise you might already have a SSH key for github # Delete the existing `id_rsa_github` to start over with the below command $ rm ~/.ssh/id_rsa_github # (optional)
-
Creating a new SSH key for GitHub
$ ssh-keygen -t rsa -b 4096 -C "[email protected]" # Above setting is Github recommend # t = type # b = bites
-
The first prompt, 🚧 Important 🚧
> Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] # !! If you press enter, will over write `id_rsa` # So, I will enter $ /Users/you/.ssh/id_rsa_github #(optional) # To make the key unique
-
The second prompt
# tread it as a password for the SSH Key > Enter passphrase (empty for no passphrase) # I using my computer password for the passphrase # You could leave it empty
-
Start the ssh-agent
$ eval "$(ssh-agent -s)" # will return: > Agent pid 59566
-
Add Identity
Add your SSH private key to the ssh-agent and store your passphrase in the keychain. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_rsa in the command with the name of your private key file.
$ ssh-add -K ~/.ssh/id_rsa_github
Note: The -K option is Apple's standard version of ssh-add, which stores the passphrase in your keychain for you when you add an ssh key to the ssh-agent.
-
Copy the new SSH Key
cat ~/.ssh/id_rsa_github.pub # Copy manually # Or, using pbcopy pbcopy < ~/.ssh/id_rsa_github.pub
-
[Add the SSH key to your GitHub account.](Add the SSH key to your GitHub account.)
- SSH to server
$ ssh servername@ip_address # Using [email protected] as example below
- Copy files
$ scp ~/test.txt [email protected]:~ # `~/` = Current Folder in local # `:~` = Server folder in root