How to reload the ssh config file in Mac OS X via terminal

When I update my ssh config file so I can switch my current github account, the changes wont work properly unless I restart iTerm. I'm working on a script to automate the github account switch and I'd like to have the script reload the config settings in the updated config file. How can I achieve this?


Solution 1:

In my case, I finally discovered that the issue wasn't the config file (ssh -vvv -F /dev/null -i /some/path/some_other_key and even moving the old keys in ~/.ssh/ elsewhere, nonetheless still managed to magick the old key out of nowhere), but rather the ssh agent. I had to clear it with ssh-add -D.

man ssh_config clarifies that -i on ssh should take precedence over the ~/.ssh/config file; so if you're doing this and it's still not working, some undocumented higher priority power is butting in.

Solution 2:

You may want to look at the Atlassian documentation on using multiple identities. A case like the one I think you're describing - switching accounts - may be best handled with an SSH config file that accommodates multiple accounts simultaneously instead of scripting.

They provide the following example for the config file at ~/.ssh/config:

# Default GitHub user
Host github.com
 HostName github.com
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/personalid

# Work user account
Host bitbucket.org
 HostName bitbucket.org
 PreferredAuthentications publickey
 IdentityFile ~/.ssh/workid