Skip to content

Instantly share code, notes, and snippets.

@rplaurindo
Last active August 21, 2023 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rplaurindo/73da83e26c0440003179 to your computer and use it in GitHub Desktop.
Save rplaurindo/73da83e26c0440003179 to your computer and use it in GitHub Desktop.

Woking With SSH Authentication

Dependencies

  • xclip

Creating folder

$ mkdir ~/.ssh

Entering inside folder

$ cd ~/.ssh

Generating a RSA key pair (public/private)

$ ssh-keygen -t rsa -b 2048 -C <email to login on git repository web page>

Appoints the file of the key and press ENTER two times.

Editing folder permissions

For security, your should edit permissions in the folder ~/.ssh

$ chmod 700 -R ~/.ssh

Adding the key

Start the SSH agent

$ eval $(ssh-agent -s)

Add private key

$ ssh-add ~/.ssh/<filename>

Obs.: the $ ssh-add command with out a file will try to add the private key contained in id_rsa file by default.

Copying the public key and pasting on git repository web page

On Linux

$ xclip -sel clip < ~/.ssh/<filename>.pub

On Windows

$ cat ~/.ssh/<file_name>.pub | clip

Testing remote connection

$ ssh -T git@<git-server-domain>

Adding a public key on a remote server on the same network

Create in the remote repository the authorized_keys file on ~/.ssh and paste the public key.

$ touch ~/.ssh/authorized_keys

$ echo "<public key>" >> ~/.ssh/authorized_keys

Working with multiple ssh key

SSH configuration

Create file config in ~/.ssh

$ touch ~/.ssh/config
$ gedit ~/.ssh/config

Insert to each repository

Host <repository-domain>:<repository-owner>
HostName <repository-domain>
IdentityFile ~/.ssh/<private_ssh_key_file_name>

Obs.: the Host key expects a pattern to differentiate from other user of the same domain. So, it cans be omitted.

Preparing the project

Run into project folder

$ git config --local remote.origin.url git@<repository-domain>:<repository-owner>/<project-path>.git
$ git config --local user.email <user-email>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment