Generate Shh Key For Git Hub


SSH Key generation, add Key to SSH Agent. GitHub Gist: instantly share code, notes, and snippets. Jul 25, 2019 This post will be pretty straightforward and will cover Windows, Mac, and Linux on how to generate SSH keys for Git authorization.

This is a small script to perform all the tasks that are necessary to create a private/public keypair forssh-authentication for password-less connecting to a remote server. Additionally it performs some checks andadjusts file-permissions both locally and on the remote server to avoid some common pitfalls.


Because I failed to remember how, every time I tried to do this manually.




You need to be able to connect to the remote server with a username and password.

Grab it
Run it

The script expects some commandline arguments which specify which key should be transferred/created andwhere it should be sent to:

You should at least set --user, --file, and --host.
If the key-file does not exist yet, a new key will be generated.

Adding ssh key to github

This will ask for the password of the target host at least once, probably twice, if the permissions are not set correctly yet.


Now you should be able to connect to the machine via ssh -i $FILENAME [email protected]$HOST.
If you use the filename~/.ssh/id_rsa you can omit the '-i' argument to ssh.


This script will remove write access to your home-directory for 'group' and 'other' on the remote server becausessh-public/private key authentication will not work otherwise.
So if there are processes running as different user,writing data to this directory may fail for them after this script is run.

Related documents


How To Generate Ssh Key Pair

Copyright 2015-2019 Dominik Stadler

Licensed under the Apache License, Version 2.0 (the 'License');you may not use this file except in compliance with the License.You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an 'AS IS' BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

Mac and Linux

  • Open Terminal

  • Check if you already have a SSH keypair generated. Do the following:

    If the files exist, you already have SSH installed. IMPORTANT: But if you wish to regenerate the SSH key pair, at least back up your old SSH keys.

  • Generate a 4096-bit key pair - yes, use the higher bit

  • Enter a file in which you want to save your keys. You can press enter and the default ~/.ssh/id_rsa will be used.

  • Enter a passphrase. Read Github working with SSH key passphrase articule on why you should use a passphrase and at the same time you don't have to enter the passphase everytime you use your SSH key.

  • From here on your SSH key pair is generated, your SSH public key is ~/.ssh/ - the one with the pub extension. BE EXTRA CAREFUL when using your ~/.ssh/id_rsa file. This is your private key, guard it properly.


  1. Install Git for Windows
  2. Open Git Bash and repeat the above instructions