The Computer Oracle

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

--------------------------------------------------
Become or hire the top 3% of the developers on Toptal https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Flying Over Ancient Lands

--

Chapters
00:00 Question
00:36 Accepted answer (Score 21)
01:31 Answer 2 (Score 6)
02:10 Answer 3 (Score 0)
02:48 Thank you

--

Full question
https://superuser.com/questions/1148766/...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#macos #bash #ssh #terminal

#avk47



ACCEPTED ANSWER

Score 23


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.




ANSWER 2

Score 6


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



ANSWER 3

Score 0


While I was looking for a way to 'refresh' the file I realised what I was actually looking for was a way to auto complete the command,

Refreshing was not necessary as @Jakuje above mentions

For those interested the auto complete script is:

complete -o default -o nospace -W "$(grep "^Host" $HOME/.ssh/config | cut -d" " -f2)" scp sftp ssh

Which I found here.

Add the above script to .bash_profile and then run source .bash_profile