Skip to content

Instantly share code, notes, and snippets.

@rsmn
Forked from jexchan/multiple_ssh_setting.md
Last active October 1, 2020 08:09
Show Gist options
  • Save rsmn/6adbcc498bd6994ba9bf27bcfa18f76f to your computer and use it in GitHub Desktop.
Save rsmn/6adbcc498bd6994ba9bf27bcfa18f76f 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!

@shotaK
Copy link

shotaK commented Oct 1, 2020

If the repo exists under other company's account try: git clone [email protected]:company/project.git

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