Skip to content

Instantly share code, notes, and snippets.

@tracer8
Forked from rsmn/multiple_ssh_setting.md
Created March 29, 2018 07:52
Show Gist options
  • Save tracer8/c36f99bce0e0302d2fa871fd65188401 to your computer and use it in GitHub Desktop.
Save tracer8/c36f99bce0e0302d2fa871fd65188401 to your computer and use it in GitHub Desktop.
How to add Multiple SSH keys to Gitlab and Add Sites from both account to Laravel Forge

Multiple SSH Keys settings for different gitlab account

Example Use Case:

  • Server: Digital Ocean
  • Server Name: serverone
  • First Gitlab Account Username: account1
  • Second Gitlab Account Username: account2

create different public key

Presumable you already have your first ssh key

~/.ssh/id_rsa

so we create a second ssh key

$ ssh-keygen -t rsa -C "root@serverone"

give the new key a different name

id_rsa_account2

So now we have 2 keys:

~/.ssh/id_rsa
~/.ssh/id_rsa_account2

Modify the ssh config

$ cd ~/.ssh/
$ touch config
$ subl -a config

Then add

#account2 account
Host gitlab.com-account2
	HostName gitlab.com
	PreferredAuthentications publickey
	IdentityFile ~/.ssh/id_rsa_account2

Go to account2 Gitlab Settings and add SSH Key

copy paste your public ssh key from here

$ cat ~/.ssh/id_rsa_account2

and add it to gitlab ssh settings

Go to Laravel Forge to add your new site

In Laravel Forge, choose Custom when installing repository, and enter the path below

[email protected]:account2/awesomeproject.git

You're good to go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment