What's the difference between Host and HostName in SSH Config?











up vote
17
down vote

favorite
4












The man page says this:



Host




Host
Restricts the following declarations (up to the next Host keyword) to be only for those hosts that match one of the patterns given after the keyword. If more than one
pattern is provided, they should be separated by whitespace. A single `*' as a pattern can be used to provide global defaults for all hosts. The host is the hostname
argument given on the command line (i.e. the name is not converted to a canonicalized host name before matching).



A pattern entry may be negated by prefixing it with an exclamation mark (`!'). If a negated entry is matched, then the Host entry is ignored, regardless of whether any
other patterns on the line match. Negated matches are therefore useful to provide exceptions for wildcard matches.>



See PATTERNS for more information on patterns.




HostName




HostName
Specifies the real host name to log into. This can be used to specify nicknames or abbreviations for hosts. If the hostname contains the character sequence `%h', then
this will be replaced with the host name specified on the command line (this is useful for manipulating unqualified names). The default is the name given on the com-
mand line. Numeric IP addresses are also permitted (both on the command line and in HostName specifications).




For example, when I want to create an SSH Config for GitHub, what should Host and HostName be respectively?










share|improve this question


















  • 2




    In essence: Host is the string the user gives as input on the CLI when invoking SSH; HostName is the string that the SSH client will output over the network when attempting to connect to the server.
    – sampablokuper
    May 26 at 1:39















up vote
17
down vote

favorite
4












The man page says this:



Host




Host
Restricts the following declarations (up to the next Host keyword) to be only for those hosts that match one of the patterns given after the keyword. If more than one
pattern is provided, they should be separated by whitespace. A single `*' as a pattern can be used to provide global defaults for all hosts. The host is the hostname
argument given on the command line (i.e. the name is not converted to a canonicalized host name before matching).



A pattern entry may be negated by prefixing it with an exclamation mark (`!'). If a negated entry is matched, then the Host entry is ignored, regardless of whether any
other patterns on the line match. Negated matches are therefore useful to provide exceptions for wildcard matches.>



See PATTERNS for more information on patterns.




HostName




HostName
Specifies the real host name to log into. This can be used to specify nicknames or abbreviations for hosts. If the hostname contains the character sequence `%h', then
this will be replaced with the host name specified on the command line (this is useful for manipulating unqualified names). The default is the name given on the com-
mand line. Numeric IP addresses are also permitted (both on the command line and in HostName specifications).




For example, when I want to create an SSH Config for GitHub, what should Host and HostName be respectively?










share|improve this question


















  • 2




    In essence: Host is the string the user gives as input on the CLI when invoking SSH; HostName is the string that the SSH client will output over the network when attempting to connect to the server.
    – sampablokuper
    May 26 at 1:39













up vote
17
down vote

favorite
4









up vote
17
down vote

favorite
4






4





The man page says this:



Host




Host
Restricts the following declarations (up to the next Host keyword) to be only for those hosts that match one of the patterns given after the keyword. If more than one
pattern is provided, they should be separated by whitespace. A single `*' as a pattern can be used to provide global defaults for all hosts. The host is the hostname
argument given on the command line (i.e. the name is not converted to a canonicalized host name before matching).



A pattern entry may be negated by prefixing it with an exclamation mark (`!'). If a negated entry is matched, then the Host entry is ignored, regardless of whether any
other patterns on the line match. Negated matches are therefore useful to provide exceptions for wildcard matches.>



See PATTERNS for more information on patterns.




HostName




HostName
Specifies the real host name to log into. This can be used to specify nicknames or abbreviations for hosts. If the hostname contains the character sequence `%h', then
this will be replaced with the host name specified on the command line (this is useful for manipulating unqualified names). The default is the name given on the com-
mand line. Numeric IP addresses are also permitted (both on the command line and in HostName specifications).




For example, when I want to create an SSH Config for GitHub, what should Host and HostName be respectively?










share|improve this question













The man page says this:



Host




Host
Restricts the following declarations (up to the next Host keyword) to be only for those hosts that match one of the patterns given after the keyword. If more than one
pattern is provided, they should be separated by whitespace. A single `*' as a pattern can be used to provide global defaults for all hosts. The host is the hostname
argument given on the command line (i.e. the name is not converted to a canonicalized host name before matching).



A pattern entry may be negated by prefixing it with an exclamation mark (`!'). If a negated entry is matched, then the Host entry is ignored, regardless of whether any
other patterns on the line match. Negated matches are therefore useful to provide exceptions for wildcard matches.>



See PATTERNS for more information on patterns.




HostName




HostName
Specifies the real host name to log into. This can be used to specify nicknames or abbreviations for hosts. If the hostname contains the character sequence `%h', then
this will be replaced with the host name specified on the command line (this is useful for manipulating unqualified names). The default is the name given on the com-
mand line. Numeric IP addresses are also permitted (both on the command line and in HostName specifications).




For example, when I want to create an SSH Config for GitHub, what should Host and HostName be respectively?







ssh






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 '12 at 2:25









0xcafebabe

362412




362412








  • 2




    In essence: Host is the string the user gives as input on the CLI when invoking SSH; HostName is the string that the SSH client will output over the network when attempting to connect to the server.
    – sampablokuper
    May 26 at 1:39














  • 2




    In essence: Host is the string the user gives as input on the CLI when invoking SSH; HostName is the string that the SSH client will output over the network when attempting to connect to the server.
    – sampablokuper
    May 26 at 1:39








2




2




In essence: Host is the string the user gives as input on the CLI when invoking SSH; HostName is the string that the SSH client will output over the network when attempting to connect to the server.
– sampablokuper
May 26 at 1:39




In essence: Host is the string the user gives as input on the CLI when invoking SSH; HostName is the string that the SSH client will output over the network when attempting to connect to the server.
– sampablokuper
May 26 at 1:39










3 Answers
3






active

oldest

votes

















up vote
13
down vote



accepted










For github.com your ~/.ssh/config might look like this



Host github.com
IdentityFile ~/.ssh/key_name_for_github


For hostname: as man says it allows you to specify abbreviation for host.
For example, if your ~/.ssh/config look like this



Host host1
HostName host1.example.com
Host host2
HostName anotherdomain.com


Then when you type





  • ssh host1 you actually login to host1.example.com


  • ssh host2 login to anotherdomain.com






share|improve this answer























  • I'm guessing that you meant 'Hostname' instead of 'Host' in your second ~/.ssh/config example?
    – Dave
    Jul 22 '16 at 19:22


















up vote
3
down vote













In simple usage:



Host is the actual hostname & there's no HostName



OR



Host is the nickname of the host & HostName is the actual hostname.



Simple example:



$ cat ~/.ssh/config
Host dev
Hostname <hostname>
User <username>
IdentityFile <path_to_private_key>

$ ssh dev
# Equivalent to "ssh -i <path_to_private_key> <username>@<hostname>"


Note: The man page is technically correct, it's just worded a bit strangely. I mentally add a few words when I read it (shown in caps): HostName Specifies the real host name to log into. This can be used TOGETHER WITH 'HOST' to specify nicknames or abbreviations for hosts.






share|improve this answer






























    up vote
    1
    down vote













    I recently wanted to do something with host and hostname, but forgot the exact syntax... but googling about it was a mess and man page wasn't too helpful. So, assuming there are others who has the same need, here are my tidbits.



    Host specifies the command line argument, and could be thought of as a) actual host name/IP, b) shorthand, c) alias. The HostName is the real hostname/IP of the machine you are connecting to. In the HostName field, you can use %h as the host name string you specify on the command line. (This was the part I wanted to use in my example.)



    So, let's say you have a set of hosts where hostname starts with my-proj-host-... and they are all in domain .my.proj.domain.com, and I need to log in to them using specific ssh key my-proj-id-rsa and specific user ID my-proj-user.
    To make my life easier, I would add the following to ~/.ssh/config file




    Host my-proj-host*



    HostName %h.my.proj.domain.com



    User my-proj-user



    IdentityFile ~/.ssh/my-proj-id-rsa




    Now, I can type in




    ssh my-proj-host-1234




    Without the config, that would have been




    ssh -i ~/.ssh/my-proj-id-rsa my-proj-user@my-proj-host-1234.my.proj.domain.com




    saving a bit of typing (and typos).






    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%2f503687%2fwhats-the-difference-between-host-and-hostname-in-ssh-config%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      13
      down vote



      accepted










      For github.com your ~/.ssh/config might look like this



      Host github.com
      IdentityFile ~/.ssh/key_name_for_github


      For hostname: as man says it allows you to specify abbreviation for host.
      For example, if your ~/.ssh/config look like this



      Host host1
      HostName host1.example.com
      Host host2
      HostName anotherdomain.com


      Then when you type





      • ssh host1 you actually login to host1.example.com


      • ssh host2 login to anotherdomain.com






      share|improve this answer























      • I'm guessing that you meant 'Hostname' instead of 'Host' in your second ~/.ssh/config example?
        – Dave
        Jul 22 '16 at 19:22















      up vote
      13
      down vote



      accepted










      For github.com your ~/.ssh/config might look like this



      Host github.com
      IdentityFile ~/.ssh/key_name_for_github


      For hostname: as man says it allows you to specify abbreviation for host.
      For example, if your ~/.ssh/config look like this



      Host host1
      HostName host1.example.com
      Host host2
      HostName anotherdomain.com


      Then when you type





      • ssh host1 you actually login to host1.example.com


      • ssh host2 login to anotherdomain.com






      share|improve this answer























      • I'm guessing that you meant 'Hostname' instead of 'Host' in your second ~/.ssh/config example?
        – Dave
        Jul 22 '16 at 19:22













      up vote
      13
      down vote



      accepted







      up vote
      13
      down vote



      accepted






      For github.com your ~/.ssh/config might look like this



      Host github.com
      IdentityFile ~/.ssh/key_name_for_github


      For hostname: as man says it allows you to specify abbreviation for host.
      For example, if your ~/.ssh/config look like this



      Host host1
      HostName host1.example.com
      Host host2
      HostName anotherdomain.com


      Then when you type





      • ssh host1 you actually login to host1.example.com


      • ssh host2 login to anotherdomain.com






      share|improve this answer














      For github.com your ~/.ssh/config might look like this



      Host github.com
      IdentityFile ~/.ssh/key_name_for_github


      For hostname: as man says it allows you to specify abbreviation for host.
      For example, if your ~/.ssh/config look like this



      Host host1
      HostName host1.example.com
      Host host2
      HostName anotherdomain.com


      Then when you type





      • ssh host1 you actually login to host1.example.com


      • ssh host2 login to anotherdomain.com







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Jun 24 '17 at 17:27









      Mr. Tao

      18118




      18118










      answered Nov 10 '12 at 3:47









      int

      37624




      37624












      • I'm guessing that you meant 'Hostname' instead of 'Host' in your second ~/.ssh/config example?
        – Dave
        Jul 22 '16 at 19:22


















      • I'm guessing that you meant 'Hostname' instead of 'Host' in your second ~/.ssh/config example?
        – Dave
        Jul 22 '16 at 19:22
















      I'm guessing that you meant 'Hostname' instead of 'Host' in your second ~/.ssh/config example?
      – Dave
      Jul 22 '16 at 19:22




      I'm guessing that you meant 'Hostname' instead of 'Host' in your second ~/.ssh/config example?
      – Dave
      Jul 22 '16 at 19:22












      up vote
      3
      down vote













      In simple usage:



      Host is the actual hostname & there's no HostName



      OR



      Host is the nickname of the host & HostName is the actual hostname.



      Simple example:



      $ cat ~/.ssh/config
      Host dev
      Hostname <hostname>
      User <username>
      IdentityFile <path_to_private_key>

      $ ssh dev
      # Equivalent to "ssh -i <path_to_private_key> <username>@<hostname>"


      Note: The man page is technically correct, it's just worded a bit strangely. I mentally add a few words when I read it (shown in caps): HostName Specifies the real host name to log into. This can be used TOGETHER WITH 'HOST' to specify nicknames or abbreviations for hosts.






      share|improve this answer



























        up vote
        3
        down vote













        In simple usage:



        Host is the actual hostname & there's no HostName



        OR



        Host is the nickname of the host & HostName is the actual hostname.



        Simple example:



        $ cat ~/.ssh/config
        Host dev
        Hostname <hostname>
        User <username>
        IdentityFile <path_to_private_key>

        $ ssh dev
        # Equivalent to "ssh -i <path_to_private_key> <username>@<hostname>"


        Note: The man page is technically correct, it's just worded a bit strangely. I mentally add a few words when I read it (shown in caps): HostName Specifies the real host name to log into. This can be used TOGETHER WITH 'HOST' to specify nicknames or abbreviations for hosts.






        share|improve this answer

























          up vote
          3
          down vote










          up vote
          3
          down vote









          In simple usage:



          Host is the actual hostname & there's no HostName



          OR



          Host is the nickname of the host & HostName is the actual hostname.



          Simple example:



          $ cat ~/.ssh/config
          Host dev
          Hostname <hostname>
          User <username>
          IdentityFile <path_to_private_key>

          $ ssh dev
          # Equivalent to "ssh -i <path_to_private_key> <username>@<hostname>"


          Note: The man page is technically correct, it's just worded a bit strangely. I mentally add a few words when I read it (shown in caps): HostName Specifies the real host name to log into. This can be used TOGETHER WITH 'HOST' to specify nicknames or abbreviations for hosts.






          share|improve this answer














          In simple usage:



          Host is the actual hostname & there's no HostName



          OR



          Host is the nickname of the host & HostName is the actual hostname.



          Simple example:



          $ cat ~/.ssh/config
          Host dev
          Hostname <hostname>
          User <username>
          IdentityFile <path_to_private_key>

          $ ssh dev
          # Equivalent to "ssh -i <path_to_private_key> <username>@<hostname>"


          Note: The man page is technically correct, it's just worded a bit strangely. I mentally add a few words when I read it (shown in caps): HostName Specifies the real host name to log into. This can be used TOGETHER WITH 'HOST' to specify nicknames or abbreviations for hosts.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 27 at 19:40

























          answered May 8 '17 at 22:46









          mblakesley

          315




          315






















              up vote
              1
              down vote













              I recently wanted to do something with host and hostname, but forgot the exact syntax... but googling about it was a mess and man page wasn't too helpful. So, assuming there are others who has the same need, here are my tidbits.



              Host specifies the command line argument, and could be thought of as a) actual host name/IP, b) shorthand, c) alias. The HostName is the real hostname/IP of the machine you are connecting to. In the HostName field, you can use %h as the host name string you specify on the command line. (This was the part I wanted to use in my example.)



              So, let's say you have a set of hosts where hostname starts with my-proj-host-... and they are all in domain .my.proj.domain.com, and I need to log in to them using specific ssh key my-proj-id-rsa and specific user ID my-proj-user.
              To make my life easier, I would add the following to ~/.ssh/config file




              Host my-proj-host*



              HostName %h.my.proj.domain.com



              User my-proj-user



              IdentityFile ~/.ssh/my-proj-id-rsa




              Now, I can type in




              ssh my-proj-host-1234




              Without the config, that would have been




              ssh -i ~/.ssh/my-proj-id-rsa my-proj-user@my-proj-host-1234.my.proj.domain.com




              saving a bit of typing (and typos).






              share|improve this answer

























                up vote
                1
                down vote













                I recently wanted to do something with host and hostname, but forgot the exact syntax... but googling about it was a mess and man page wasn't too helpful. So, assuming there are others who has the same need, here are my tidbits.



                Host specifies the command line argument, and could be thought of as a) actual host name/IP, b) shorthand, c) alias. The HostName is the real hostname/IP of the machine you are connecting to. In the HostName field, you can use %h as the host name string you specify on the command line. (This was the part I wanted to use in my example.)



                So, let's say you have a set of hosts where hostname starts with my-proj-host-... and they are all in domain .my.proj.domain.com, and I need to log in to them using specific ssh key my-proj-id-rsa and specific user ID my-proj-user.
                To make my life easier, I would add the following to ~/.ssh/config file




                Host my-proj-host*



                HostName %h.my.proj.domain.com



                User my-proj-user



                IdentityFile ~/.ssh/my-proj-id-rsa




                Now, I can type in




                ssh my-proj-host-1234




                Without the config, that would have been




                ssh -i ~/.ssh/my-proj-id-rsa my-proj-user@my-proj-host-1234.my.proj.domain.com




                saving a bit of typing (and typos).






                share|improve this answer























                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  I recently wanted to do something with host and hostname, but forgot the exact syntax... but googling about it was a mess and man page wasn't too helpful. So, assuming there are others who has the same need, here are my tidbits.



                  Host specifies the command line argument, and could be thought of as a) actual host name/IP, b) shorthand, c) alias. The HostName is the real hostname/IP of the machine you are connecting to. In the HostName field, you can use %h as the host name string you specify on the command line. (This was the part I wanted to use in my example.)



                  So, let's say you have a set of hosts where hostname starts with my-proj-host-... and they are all in domain .my.proj.domain.com, and I need to log in to them using specific ssh key my-proj-id-rsa and specific user ID my-proj-user.
                  To make my life easier, I would add the following to ~/.ssh/config file




                  Host my-proj-host*



                  HostName %h.my.proj.domain.com



                  User my-proj-user



                  IdentityFile ~/.ssh/my-proj-id-rsa




                  Now, I can type in




                  ssh my-proj-host-1234




                  Without the config, that would have been




                  ssh -i ~/.ssh/my-proj-id-rsa my-proj-user@my-proj-host-1234.my.proj.domain.com




                  saving a bit of typing (and typos).






                  share|improve this answer












                  I recently wanted to do something with host and hostname, but forgot the exact syntax... but googling about it was a mess and man page wasn't too helpful. So, assuming there are others who has the same need, here are my tidbits.



                  Host specifies the command line argument, and could be thought of as a) actual host name/IP, b) shorthand, c) alias. The HostName is the real hostname/IP of the machine you are connecting to. In the HostName field, you can use %h as the host name string you specify on the command line. (This was the part I wanted to use in my example.)



                  So, let's say you have a set of hosts where hostname starts with my-proj-host-... and they are all in domain .my.proj.domain.com, and I need to log in to them using specific ssh key my-proj-id-rsa and specific user ID my-proj-user.
                  To make my life easier, I would add the following to ~/.ssh/config file




                  Host my-proj-host*



                  HostName %h.my.proj.domain.com



                  User my-proj-user



                  IdentityFile ~/.ssh/my-proj-id-rsa




                  Now, I can type in




                  ssh my-proj-host-1234




                  Without the config, that would have been




                  ssh -i ~/.ssh/my-proj-id-rsa my-proj-user@my-proj-host-1234.my.proj.domain.com




                  saving a bit of typing (and typos).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 16 at 18:40









                  Marcus Yoo

                  311




                  311






























                      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%2f503687%2fwhats-the-difference-between-host-and-hostname-in-ssh-config%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

                      flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                      Mangá

                       ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕