Skip to content

Instantly share code, notes, and snippets.

@max8hine
Created September 14, 2019 04:21
Show Gist options
  • Save max8hine/1db138d7f8ee7e8ca5a09dfbc91ddb80 to your computer and use it in GitHub Desktop.
Save max8hine/1db138d7f8ee7e8ca5a09dfbc91ddb80 to your computer and use it in GitHub Desktop.
SSH Key, Tips

Connect Github by Using SSH Key on macOS

Based on Github Doc, and clarified the confusing parts

  1. Open Terminal

  2. 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)
  3. Creating a new SSH key for GitHub

    $ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    # Above setting is Github recommend
    # t = type
    # b = bites
  4. 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
  5. 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
  6. Start the ssh-agent

    $ eval "$(ssh-agent -s)"
    # will return: > Agent pid 59566
  7. 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.

  8. Copy the new SSH Key

    cat ~/.ssh/id_rsa_github.pub # Copy manually
    # Or, using pbcopy
    pbcopy < ~/.ssh/id_rsa_github.pub
  9. [Add the SSH key to your GitHub account.](Add the SSH key to your GitHub account.)

SiteHost

  1. SSH to server
    $ ssh servername@ip_address
    # Using brad@192.168.1.29 as example below
  2. Copy files
    $ scp ~/test.txt brad@192.168.1.29:~
    # `~/` = Current Folder in local
    # `:~` = Server folder in root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment