SSH config
I first encountered the SSH config when I had to set up SSH for two BitBucket accounts. One work, and one personal. Requiring separate login credentials, setting the remote on Git repositories to ssh://git@bitbucket.org/...
wasn’t going to work.
Each BitBucket account requires a different public SSH key so for two accounts I needed to generate two sets of keys. You’ll likely already have a keyset called id_rsa
so call the new one something else:
|
|
Now in your ~/.ssh/
directory create a new file simply called config
, for my example it looks like this:
|
|
Now instead of bitbucket.org in my git remote URIs I substitute the relevant Host from my config:
|
|
Of course, you need to ensure the public key is configured over on BitBucket, GitHub etc.
To use config
with your own remote machines is just as easy. You can use any of the keys you already have on your system, or create a new one as shown above.
If it doesn’t exist, create a file in the ~/.ssh/
directory on your remote machine called authorized_keys
and copy the public key in to it, each one on a new line. Never the private key!
Now in your config
file on your local machine create a new host for your remote machine:
|
|
Strictly speaking, I don’t think the User
line is necessary.
Now all I need to type in the terminal to ssh in to my production box is:
|
|