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











up vote
5
down vote

favorite












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?










share|improve this question


















  • 1




    How, do you switch accounts? Do you use ssh-agent? The ssh_config is read for every single invocation of ssh.
    – Jakuje
    Nov 23 '16 at 8:44










  • Can you give us more detail about the config file? Also, could you define different hosts for the different github accounts, and avoid the reloading problem?
    – JasKerr
    Nov 24 '16 at 2:45















up vote
5
down vote

favorite












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?










share|improve this question


















  • 1




    How, do you switch accounts? Do you use ssh-agent? The ssh_config is read for every single invocation of ssh.
    – Jakuje
    Nov 23 '16 at 8:44










  • Can you give us more detail about the config file? Also, could you define different hosts for the different github accounts, and avoid the reloading problem?
    – JasKerr
    Nov 24 '16 at 2:45













up vote
5
down vote

favorite









up vote
5
down vote

favorite











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?










share|improve this question













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?







macos bash ssh terminal






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 22 '16 at 22:20









Daniel Jacobson

150127




150127








  • 1




    How, do you switch accounts? Do you use ssh-agent? The ssh_config is read for every single invocation of ssh.
    – Jakuje
    Nov 23 '16 at 8:44










  • Can you give us more detail about the config file? Also, could you define different hosts for the different github accounts, and avoid the reloading problem?
    – JasKerr
    Nov 24 '16 at 2:45














  • 1




    How, do you switch accounts? Do you use ssh-agent? The ssh_config is read for every single invocation of ssh.
    – Jakuje
    Nov 23 '16 at 8:44










  • Can you give us more detail about the config file? Also, could you define different hosts for the different github accounts, and avoid the reloading problem?
    – JasKerr
    Nov 24 '16 at 2:45








1




1




How, do you switch accounts? Do you use ssh-agent? The ssh_config is read for every single invocation of ssh.
– Jakuje
Nov 23 '16 at 8:44




How, do you switch accounts? Do you use ssh-agent? The ssh_config is read for every single invocation of ssh.
– Jakuje
Nov 23 '16 at 8:44












Can you give us more detail about the config file? Also, could you define different hosts for the different github accounts, and avoid the reloading problem?
– JasKerr
Nov 24 '16 at 2:45




Can you give us more detail about the config file? Also, could you define different hosts for the different github accounts, and avoid the reloading problem?
– JasKerr
Nov 24 '16 at 2:45










2 Answers
2






active

oldest

votes

















up vote
0
down vote













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





share|improve this answer

















  • 1




    Note you could also use different Host nicknames for the same HostName, with different IdentityFiles for each: Host github-charlie, Host github-sam
    – jpaugh
    Feb 5 at 14:56




















up vote
0
down vote













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






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1148766%2fhow-to-reload-the-ssh-config-file-in-mac-os-x-via-terminal%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    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





    share|improve this answer

















    • 1




      Note you could also use different Host nicknames for the same HostName, with different IdentityFiles for each: Host github-charlie, Host github-sam
      – jpaugh
      Feb 5 at 14:56

















    up vote
    0
    down vote













    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





    share|improve this answer

















    • 1




      Note you could also use different Host nicknames for the same HostName, with different IdentityFiles for each: Host github-charlie, Host github-sam
      – jpaugh
      Feb 5 at 14:56















    up vote
    0
    down vote










    up vote
    0
    down vote









    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





    share|improve this answer












    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






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered May 16 '17 at 17:39









    user2623888

    1




    1








    • 1




      Note you could also use different Host nicknames for the same HostName, with different IdentityFiles for each: Host github-charlie, Host github-sam
      – jpaugh
      Feb 5 at 14:56
















    • 1




      Note you could also use different Host nicknames for the same HostName, with different IdentityFiles for each: Host github-charlie, Host github-sam
      – jpaugh
      Feb 5 at 14:56










    1




    1




    Note you could also use different Host nicknames for the same HostName, with different IdentityFiles for each: Host github-charlie, Host github-sam
    – jpaugh
    Feb 5 at 14:56






    Note you could also use different Host nicknames for the same HostName, with different IdentityFiles for each: Host github-charlie, Host github-sam
    – jpaugh
    Feb 5 at 14:56














    up vote
    0
    down vote













    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






    share|improve this answer

























      up vote
      0
      down vote













      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






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        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






        share|improve this answer












        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Sep 3 at 15:50









        Tomos Williams

        1011




        1011






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Super User!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1148766%2fhow-to-reload-the-ssh-config-file-in-mac-os-x-via-terminal%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            QoS: MAC-Priority for clients behind a repeater

            Ивакино (Тотемский район)

            Can't locate Autom4te/ChannelDefs.pm in @INC (when it definitely is there)