How to save a frequently used SSH host for access via terminal? [duplicate]





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







25
















This question already has an answer here:




  • Host alias for ssh

    2 answers




I have a host that I frequently ssh into. But I don't want to enter it again and again. Should I use an environment variable for this or is there a better way?



I wouldn't mind a generalized solution on saving frequently used variables that exist outside of a single bash session.










share|improve this question















marked as duplicate by Eric Carvalho, Pilot6, Charles Green, Volker Siegel, Thomas Feb 24 at 9:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 3





    How about saving the params in ~/.ssh/config? Some examples are here: nerderati.com/2011/03/17/…

    – user000001
    Feb 14 at 7:31








  • 4





    To expand on Roger's comment, URLs are those things that have the format of <protocol>://<host>:<port>/<path> (simplified example). The syntax ssh uses to specify locations is different. ssh ssh://user@server:22/ would be invalid.

    – JoL
    Feb 14 at 20:06








  • 6





    Possible duplicate of Host alias for ssh, and this and probably a few more.

    – Sparhawk
    Feb 16 at 6:22




















25
















This question already has an answer here:




  • Host alias for ssh

    2 answers




I have a host that I frequently ssh into. But I don't want to enter it again and again. Should I use an environment variable for this or is there a better way?



I wouldn't mind a generalized solution on saving frequently used variables that exist outside of a single bash session.










share|improve this question















marked as duplicate by Eric Carvalho, Pilot6, Charles Green, Volker Siegel, Thomas Feb 24 at 9:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 3





    How about saving the params in ~/.ssh/config? Some examples are here: nerderati.com/2011/03/17/…

    – user000001
    Feb 14 at 7:31








  • 4





    To expand on Roger's comment, URLs are those things that have the format of <protocol>://<host>:<port>/<path> (simplified example). The syntax ssh uses to specify locations is different. ssh ssh://user@server:22/ would be invalid.

    – JoL
    Feb 14 at 20:06








  • 6





    Possible duplicate of Host alias for ssh, and this and probably a few more.

    – Sparhawk
    Feb 16 at 6:22
















25












25








25


7







This question already has an answer here:




  • Host alias for ssh

    2 answers




I have a host that I frequently ssh into. But I don't want to enter it again and again. Should I use an environment variable for this or is there a better way?



I wouldn't mind a generalized solution on saving frequently used variables that exist outside of a single bash session.










share|improve this question

















This question already has an answer here:




  • Host alias for ssh

    2 answers




I have a host that I frequently ssh into. But I don't want to enter it again and again. Should I use an environment variable for this or is there a better way?



I wouldn't mind a generalized solution on saving frequently used variables that exist outside of a single bash session.





This question already has an answer here:




  • Host alias for ssh

    2 answers








command-line bash ssh environment-variables






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 18 at 9:08







Vaish MK

















asked Feb 14 at 7:27









Vaish MKVaish MK

12826




12826




marked as duplicate by Eric Carvalho, Pilot6, Charles Green, Volker Siegel, Thomas Feb 24 at 9:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Eric Carvalho, Pilot6, Charles Green, Volker Siegel, Thomas Feb 24 at 9:55


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 3





    How about saving the params in ~/.ssh/config? Some examples are here: nerderati.com/2011/03/17/…

    – user000001
    Feb 14 at 7:31








  • 4





    To expand on Roger's comment, URLs are those things that have the format of <protocol>://<host>:<port>/<path> (simplified example). The syntax ssh uses to specify locations is different. ssh ssh://user@server:22/ would be invalid.

    – JoL
    Feb 14 at 20:06








  • 6





    Possible duplicate of Host alias for ssh, and this and probably a few more.

    – Sparhawk
    Feb 16 at 6:22
















  • 3





    How about saving the params in ~/.ssh/config? Some examples are here: nerderati.com/2011/03/17/…

    – user000001
    Feb 14 at 7:31








  • 4





    To expand on Roger's comment, URLs are those things that have the format of <protocol>://<host>:<port>/<path> (simplified example). The syntax ssh uses to specify locations is different. ssh ssh://user@server:22/ would be invalid.

    – JoL
    Feb 14 at 20:06








  • 6





    Possible duplicate of Host alias for ssh, and this and probably a few more.

    – Sparhawk
    Feb 16 at 6:22










3




3





How about saving the params in ~/.ssh/config? Some examples are here: nerderati.com/2011/03/17/…

– user000001
Feb 14 at 7:31







How about saving the params in ~/.ssh/config? Some examples are here: nerderati.com/2011/03/17/…

– user000001
Feb 14 at 7:31






4




4





To expand on Roger's comment, URLs are those things that have the format of <protocol>://<host>:<port>/<path> (simplified example). The syntax ssh uses to specify locations is different. ssh ssh://user@server:22/ would be invalid.

– JoL
Feb 14 at 20:06







To expand on Roger's comment, URLs are those things that have the format of <protocol>://<host>:<port>/<path> (simplified example). The syntax ssh uses to specify locations is different. ssh ssh://user@server:22/ would be invalid.

– JoL
Feb 14 at 20:06






6




6





Possible duplicate of Host alias for ssh, and this and probably a few more.

– Sparhawk
Feb 16 at 6:22







Possible duplicate of Host alias for ssh, and this and probably a few more.

– Sparhawk
Feb 16 at 6:22












5 Answers
5






active

oldest

votes


















44














Environment variables are for the purpose of communicating information to multiple commands/processes that you start in shell that commands or processes expect to be there in the environment. Usually such variables include options, such as LESS variable passing frequently-used options to less pager, PERL5LIB for finding perl modules in non-standard locations, LC_LANG to communicate which language a command should use for the output.



If the URL is for your own use with a specific command, use an alias such as alias au='firefox https://askubuntu.com or a function such as open_url(){ firefox "$@" } to open arbitrary URL that you provide on command-line as positional parameter to the function.



In certain cases such as ssh, you can define connection properties in configuration files as explained in Lekensteyn's answer:





  1. define ~/.ssh/config file with the following contents



    Host meh
    HostName meh.example.com
    User admin
    Port 1234
    IdentityFile ~/.ssh/id_rsa


  2. use ssh meh to connect to the host using the config file.







share|improve this answer





















  • 2





    I'd also use IdentitiesOnly yes .

    – Giacomo Alzetta
    Feb 14 at 10:59











  • Also note that by default on Ubuntu, tab completion works with ssh hosts named in the config file.

    – Roger Lipscombe
    Feb 15 at 18:57






  • 1





    @Dubu I don't understand your comment. The answer clearly contains URLs. Are you saying it doesn't?

    – Jon Bentley
    Feb 15 at 19:04











  • I think the URL comment comes from referring to the connection properties in the config file as a "URL" which is not strictly accurate. I changed that wording.

    – user459652
    Feb 15 at 21:47



















13














Also I would suggest to create an alias.



Edit your .bashrc (or maybe .profile or similar file) in your home directory. Add several aliases like:



alias go='ssh url1'
alias go2='ssh url2'


Then, relogin/reconnect and enter go or go2.






share|improve this answer

































    7














    I'd suggest combining Sergiy's and Lewis's answers for maximum laziness efficiency:



    First create a host entry for ssh:



    define ~/.ssh/config file with the following contents



        Host meh
    HostName meh.example.com
    User admin
    Port 1234
    IdentityFile ~/.ssh/id_rsa


    Now ssh meh works, but that could still be quite long. There is autocompletion (after ssh[Blank]), but its still an awful lot to type.



    So lets also define an alias:



    Edit your .bashrc in your local home directory. Add an alias like:



    alias meh='ssh meh'


    Now you can connect to "meh.example.com" by simply typing meh in your terminal window.
    If instead of "meh" you want to use a longer string, you can actually use [Tab] key to autocomplete.



    Or if you are really lazy, just define a single character as alias:



    alias m='ssh meh'


    So, if you type m and hit Enter/Return, your ssh connection will start immediately !






    share|improve this answer


























    • I think autocomplete for ssh-config 'just works' on ubuntu, and has worked as far as I can remember, the only place where I know it doesn't work out-of-the-box is MacOS

      – Pelle
      Feb 15 at 14:37











    • @Pelle, yes that's true! I better rephrase that... But you have to type out the whole of ssh plus the blank and at least the first character.. which is so much work if you have to do it often.. and as sysadmin you should be lazy ;)

      – Robert Riedl
      Feb 15 at 14:42











    • It's not clear from your answer what the benefit of combining the two approaches is, over just using the bash alias (of course I agree there is a benefit).

      – Jon Bentley
      Feb 15 at 20:05











    • @Jon Bentley, hm... I'll have a look tomorrow and see how I can make this clear.

      – Robert Riedl
      Feb 15 at 20:19











    • Sure. And just to elaborate on my comment a little, I'm contrasting this approach with doing a alias meh='ssh admin@meh.example.com -p 1234 -i ~/.ssh/id_rsa' which would achieve the same thing. The benefit I am thinking of of using the config file is that you can enforce the IdentitiesOnly yes option. Also that it feels more "correct" to store your SSH hosts in config rather than in some bash alias.

      – Jon Bentley
      Feb 15 at 20:25





















    5














    Yet another option is to use the history features of the shell. You can Ctrl-r in bash and type a unique substring of the last time you ssh'ed to that place. If there's no unique substring, you can just use whatever qualifies best as a rare substring and browse through the history entries by repeatedly pressing Ctr-r until you get to it. For example, you might type Ctrl-r and "monkeys" or "codemonkeys" or "odemon" or "kong" and get



    ssh kong@codemonkeys.some-server.com


    from the last, and hopefully only time you typed that whole.



    With the history features of the shell, there's really no reason to type any long command more than once.






    share|improve this answer

































      3














      I usually just create a .sh which contains a ssh command. For example:



      # file name: mywebsite-live.sh
      ssh username@123.123.123.123 # or whatever the domain is.


      And then to run it I simply do ./mywebsite-live.sh



      I realise that it's probably a pretty crappy solution but it works for me and the hope is that it might work for someone else too.






      share|improve this answer






























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        44














        Environment variables are for the purpose of communicating information to multiple commands/processes that you start in shell that commands or processes expect to be there in the environment. Usually such variables include options, such as LESS variable passing frequently-used options to less pager, PERL5LIB for finding perl modules in non-standard locations, LC_LANG to communicate which language a command should use for the output.



        If the URL is for your own use with a specific command, use an alias such as alias au='firefox https://askubuntu.com or a function such as open_url(){ firefox "$@" } to open arbitrary URL that you provide on command-line as positional parameter to the function.



        In certain cases such as ssh, you can define connection properties in configuration files as explained in Lekensteyn's answer:





        1. define ~/.ssh/config file with the following contents



          Host meh
          HostName meh.example.com
          User admin
          Port 1234
          IdentityFile ~/.ssh/id_rsa


        2. use ssh meh to connect to the host using the config file.







        share|improve this answer





















        • 2





          I'd also use IdentitiesOnly yes .

          – Giacomo Alzetta
          Feb 14 at 10:59











        • Also note that by default on Ubuntu, tab completion works with ssh hosts named in the config file.

          – Roger Lipscombe
          Feb 15 at 18:57






        • 1





          @Dubu I don't understand your comment. The answer clearly contains URLs. Are you saying it doesn't?

          – Jon Bentley
          Feb 15 at 19:04











        • I think the URL comment comes from referring to the connection properties in the config file as a "URL" which is not strictly accurate. I changed that wording.

          – user459652
          Feb 15 at 21:47
















        44














        Environment variables are for the purpose of communicating information to multiple commands/processes that you start in shell that commands or processes expect to be there in the environment. Usually such variables include options, such as LESS variable passing frequently-used options to less pager, PERL5LIB for finding perl modules in non-standard locations, LC_LANG to communicate which language a command should use for the output.



        If the URL is for your own use with a specific command, use an alias such as alias au='firefox https://askubuntu.com or a function such as open_url(){ firefox "$@" } to open arbitrary URL that you provide on command-line as positional parameter to the function.



        In certain cases such as ssh, you can define connection properties in configuration files as explained in Lekensteyn's answer:





        1. define ~/.ssh/config file with the following contents



          Host meh
          HostName meh.example.com
          User admin
          Port 1234
          IdentityFile ~/.ssh/id_rsa


        2. use ssh meh to connect to the host using the config file.







        share|improve this answer





















        • 2





          I'd also use IdentitiesOnly yes .

          – Giacomo Alzetta
          Feb 14 at 10:59











        • Also note that by default on Ubuntu, tab completion works with ssh hosts named in the config file.

          – Roger Lipscombe
          Feb 15 at 18:57






        • 1





          @Dubu I don't understand your comment. The answer clearly contains URLs. Are you saying it doesn't?

          – Jon Bentley
          Feb 15 at 19:04











        • I think the URL comment comes from referring to the connection properties in the config file as a "URL" which is not strictly accurate. I changed that wording.

          – user459652
          Feb 15 at 21:47














        44












        44








        44







        Environment variables are for the purpose of communicating information to multiple commands/processes that you start in shell that commands or processes expect to be there in the environment. Usually such variables include options, such as LESS variable passing frequently-used options to less pager, PERL5LIB for finding perl modules in non-standard locations, LC_LANG to communicate which language a command should use for the output.



        If the URL is for your own use with a specific command, use an alias such as alias au='firefox https://askubuntu.com or a function such as open_url(){ firefox "$@" } to open arbitrary URL that you provide on command-line as positional parameter to the function.



        In certain cases such as ssh, you can define connection properties in configuration files as explained in Lekensteyn's answer:





        1. define ~/.ssh/config file with the following contents



          Host meh
          HostName meh.example.com
          User admin
          Port 1234
          IdentityFile ~/.ssh/id_rsa


        2. use ssh meh to connect to the host using the config file.







        share|improve this answer















        Environment variables are for the purpose of communicating information to multiple commands/processes that you start in shell that commands or processes expect to be there in the environment. Usually such variables include options, such as LESS variable passing frequently-used options to less pager, PERL5LIB for finding perl modules in non-standard locations, LC_LANG to communicate which language a command should use for the output.



        If the URL is for your own use with a specific command, use an alias such as alias au='firefox https://askubuntu.com or a function such as open_url(){ firefox "$@" } to open arbitrary URL that you provide on command-line as positional parameter to the function.



        In certain cases such as ssh, you can define connection properties in configuration files as explained in Lekensteyn's answer:





        1. define ~/.ssh/config file with the following contents



          Host meh
          HostName meh.example.com
          User admin
          Port 1234
          IdentityFile ~/.ssh/id_rsa


        2. use ssh meh to connect to the host using the config file.








        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Feb 15 at 21:46







        user459652

















        answered Feb 14 at 7:32









        Sergiy KolodyazhnyySergiy Kolodyazhnyy

        75.3k9155328




        75.3k9155328








        • 2





          I'd also use IdentitiesOnly yes .

          – Giacomo Alzetta
          Feb 14 at 10:59











        • Also note that by default on Ubuntu, tab completion works with ssh hosts named in the config file.

          – Roger Lipscombe
          Feb 15 at 18:57






        • 1





          @Dubu I don't understand your comment. The answer clearly contains URLs. Are you saying it doesn't?

          – Jon Bentley
          Feb 15 at 19:04











        • I think the URL comment comes from referring to the connection properties in the config file as a "URL" which is not strictly accurate. I changed that wording.

          – user459652
          Feb 15 at 21:47














        • 2





          I'd also use IdentitiesOnly yes .

          – Giacomo Alzetta
          Feb 14 at 10:59











        • Also note that by default on Ubuntu, tab completion works with ssh hosts named in the config file.

          – Roger Lipscombe
          Feb 15 at 18:57






        • 1





          @Dubu I don't understand your comment. The answer clearly contains URLs. Are you saying it doesn't?

          – Jon Bentley
          Feb 15 at 19:04











        • I think the URL comment comes from referring to the connection properties in the config file as a "URL" which is not strictly accurate. I changed that wording.

          – user459652
          Feb 15 at 21:47








        2




        2





        I'd also use IdentitiesOnly yes .

        – Giacomo Alzetta
        Feb 14 at 10:59





        I'd also use IdentitiesOnly yes .

        – Giacomo Alzetta
        Feb 14 at 10:59













        Also note that by default on Ubuntu, tab completion works with ssh hosts named in the config file.

        – Roger Lipscombe
        Feb 15 at 18:57





        Also note that by default on Ubuntu, tab completion works with ssh hosts named in the config file.

        – Roger Lipscombe
        Feb 15 at 18:57




        1




        1





        @Dubu I don't understand your comment. The answer clearly contains URLs. Are you saying it doesn't?

        – Jon Bentley
        Feb 15 at 19:04





        @Dubu I don't understand your comment. The answer clearly contains URLs. Are you saying it doesn't?

        – Jon Bentley
        Feb 15 at 19:04













        I think the URL comment comes from referring to the connection properties in the config file as a "URL" which is not strictly accurate. I changed that wording.

        – user459652
        Feb 15 at 21:47





        I think the URL comment comes from referring to the connection properties in the config file as a "URL" which is not strictly accurate. I changed that wording.

        – user459652
        Feb 15 at 21:47













        13














        Also I would suggest to create an alias.



        Edit your .bashrc (or maybe .profile or similar file) in your home directory. Add several aliases like:



        alias go='ssh url1'
        alias go2='ssh url2'


        Then, relogin/reconnect and enter go or go2.






        share|improve this answer






























          13














          Also I would suggest to create an alias.



          Edit your .bashrc (or maybe .profile or similar file) in your home directory. Add several aliases like:



          alias go='ssh url1'
          alias go2='ssh url2'


          Then, relogin/reconnect and enter go or go2.






          share|improve this answer




























            13












            13








            13







            Also I would suggest to create an alias.



            Edit your .bashrc (or maybe .profile or similar file) in your home directory. Add several aliases like:



            alias go='ssh url1'
            alias go2='ssh url2'


            Then, relogin/reconnect and enter go or go2.






            share|improve this answer















            Also I would suggest to create an alias.



            Edit your .bashrc (or maybe .profile or similar file) in your home directory. Add several aliases like:



            alias go='ssh url1'
            alias go2='ssh url2'


            Then, relogin/reconnect and enter go or go2.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 14 at 14:40









            dessert

            25.5k674108




            25.5k674108










            answered Feb 14 at 12:48









            Lewis BLewis B

            1392




            1392























                7














                I'd suggest combining Sergiy's and Lewis's answers for maximum laziness efficiency:



                First create a host entry for ssh:



                define ~/.ssh/config file with the following contents



                    Host meh
                HostName meh.example.com
                User admin
                Port 1234
                IdentityFile ~/.ssh/id_rsa


                Now ssh meh works, but that could still be quite long. There is autocompletion (after ssh[Blank]), but its still an awful lot to type.



                So lets also define an alias:



                Edit your .bashrc in your local home directory. Add an alias like:



                alias meh='ssh meh'


                Now you can connect to "meh.example.com" by simply typing meh in your terminal window.
                If instead of "meh" you want to use a longer string, you can actually use [Tab] key to autocomplete.



                Or if you are really lazy, just define a single character as alias:



                alias m='ssh meh'


                So, if you type m and hit Enter/Return, your ssh connection will start immediately !






                share|improve this answer


























                • I think autocomplete for ssh-config 'just works' on ubuntu, and has worked as far as I can remember, the only place where I know it doesn't work out-of-the-box is MacOS

                  – Pelle
                  Feb 15 at 14:37











                • @Pelle, yes that's true! I better rephrase that... But you have to type out the whole of ssh plus the blank and at least the first character.. which is so much work if you have to do it often.. and as sysadmin you should be lazy ;)

                  – Robert Riedl
                  Feb 15 at 14:42











                • It's not clear from your answer what the benefit of combining the two approaches is, over just using the bash alias (of course I agree there is a benefit).

                  – Jon Bentley
                  Feb 15 at 20:05











                • @Jon Bentley, hm... I'll have a look tomorrow and see how I can make this clear.

                  – Robert Riedl
                  Feb 15 at 20:19











                • Sure. And just to elaborate on my comment a little, I'm contrasting this approach with doing a alias meh='ssh admin@meh.example.com -p 1234 -i ~/.ssh/id_rsa' which would achieve the same thing. The benefit I am thinking of of using the config file is that you can enforce the IdentitiesOnly yes option. Also that it feels more "correct" to store your SSH hosts in config rather than in some bash alias.

                  – Jon Bentley
                  Feb 15 at 20:25


















                7














                I'd suggest combining Sergiy's and Lewis's answers for maximum laziness efficiency:



                First create a host entry for ssh:



                define ~/.ssh/config file with the following contents



                    Host meh
                HostName meh.example.com
                User admin
                Port 1234
                IdentityFile ~/.ssh/id_rsa


                Now ssh meh works, but that could still be quite long. There is autocompletion (after ssh[Blank]), but its still an awful lot to type.



                So lets also define an alias:



                Edit your .bashrc in your local home directory. Add an alias like:



                alias meh='ssh meh'


                Now you can connect to "meh.example.com" by simply typing meh in your terminal window.
                If instead of "meh" you want to use a longer string, you can actually use [Tab] key to autocomplete.



                Or if you are really lazy, just define a single character as alias:



                alias m='ssh meh'


                So, if you type m and hit Enter/Return, your ssh connection will start immediately !






                share|improve this answer


























                • I think autocomplete for ssh-config 'just works' on ubuntu, and has worked as far as I can remember, the only place where I know it doesn't work out-of-the-box is MacOS

                  – Pelle
                  Feb 15 at 14:37











                • @Pelle, yes that's true! I better rephrase that... But you have to type out the whole of ssh plus the blank and at least the first character.. which is so much work if you have to do it often.. and as sysadmin you should be lazy ;)

                  – Robert Riedl
                  Feb 15 at 14:42











                • It's not clear from your answer what the benefit of combining the two approaches is, over just using the bash alias (of course I agree there is a benefit).

                  – Jon Bentley
                  Feb 15 at 20:05











                • @Jon Bentley, hm... I'll have a look tomorrow and see how I can make this clear.

                  – Robert Riedl
                  Feb 15 at 20:19











                • Sure. And just to elaborate on my comment a little, I'm contrasting this approach with doing a alias meh='ssh admin@meh.example.com -p 1234 -i ~/.ssh/id_rsa' which would achieve the same thing. The benefit I am thinking of of using the config file is that you can enforce the IdentitiesOnly yes option. Also that it feels more "correct" to store your SSH hosts in config rather than in some bash alias.

                  – Jon Bentley
                  Feb 15 at 20:25
















                7












                7








                7







                I'd suggest combining Sergiy's and Lewis's answers for maximum laziness efficiency:



                First create a host entry for ssh:



                define ~/.ssh/config file with the following contents



                    Host meh
                HostName meh.example.com
                User admin
                Port 1234
                IdentityFile ~/.ssh/id_rsa


                Now ssh meh works, but that could still be quite long. There is autocompletion (after ssh[Blank]), but its still an awful lot to type.



                So lets also define an alias:



                Edit your .bashrc in your local home directory. Add an alias like:



                alias meh='ssh meh'


                Now you can connect to "meh.example.com" by simply typing meh in your terminal window.
                If instead of "meh" you want to use a longer string, you can actually use [Tab] key to autocomplete.



                Or if you are really lazy, just define a single character as alias:



                alias m='ssh meh'


                So, if you type m and hit Enter/Return, your ssh connection will start immediately !






                share|improve this answer















                I'd suggest combining Sergiy's and Lewis's answers for maximum laziness efficiency:



                First create a host entry for ssh:



                define ~/.ssh/config file with the following contents



                    Host meh
                HostName meh.example.com
                User admin
                Port 1234
                IdentityFile ~/.ssh/id_rsa


                Now ssh meh works, but that could still be quite long. There is autocompletion (after ssh[Blank]), but its still an awful lot to type.



                So lets also define an alias:



                Edit your .bashrc in your local home directory. Add an alias like:



                alias meh='ssh meh'


                Now you can connect to "meh.example.com" by simply typing meh in your terminal window.
                If instead of "meh" you want to use a longer string, you can actually use [Tab] key to autocomplete.



                Or if you are really lazy, just define a single character as alias:



                alias m='ssh meh'


                So, if you type m and hit Enter/Return, your ssh connection will start immediately !







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Feb 15 at 14:44

























                answered Feb 15 at 8:23









                Robert RiedlRobert Riedl

                3,205927




                3,205927













                • I think autocomplete for ssh-config 'just works' on ubuntu, and has worked as far as I can remember, the only place where I know it doesn't work out-of-the-box is MacOS

                  – Pelle
                  Feb 15 at 14:37











                • @Pelle, yes that's true! I better rephrase that... But you have to type out the whole of ssh plus the blank and at least the first character.. which is so much work if you have to do it often.. and as sysadmin you should be lazy ;)

                  – Robert Riedl
                  Feb 15 at 14:42











                • It's not clear from your answer what the benefit of combining the two approaches is, over just using the bash alias (of course I agree there is a benefit).

                  – Jon Bentley
                  Feb 15 at 20:05











                • @Jon Bentley, hm... I'll have a look tomorrow and see how I can make this clear.

                  – Robert Riedl
                  Feb 15 at 20:19











                • Sure. And just to elaborate on my comment a little, I'm contrasting this approach with doing a alias meh='ssh admin@meh.example.com -p 1234 -i ~/.ssh/id_rsa' which would achieve the same thing. The benefit I am thinking of of using the config file is that you can enforce the IdentitiesOnly yes option. Also that it feels more "correct" to store your SSH hosts in config rather than in some bash alias.

                  – Jon Bentley
                  Feb 15 at 20:25





















                • I think autocomplete for ssh-config 'just works' on ubuntu, and has worked as far as I can remember, the only place where I know it doesn't work out-of-the-box is MacOS

                  – Pelle
                  Feb 15 at 14:37











                • @Pelle, yes that's true! I better rephrase that... But you have to type out the whole of ssh plus the blank and at least the first character.. which is so much work if you have to do it often.. and as sysadmin you should be lazy ;)

                  – Robert Riedl
                  Feb 15 at 14:42











                • It's not clear from your answer what the benefit of combining the two approaches is, over just using the bash alias (of course I agree there is a benefit).

                  – Jon Bentley
                  Feb 15 at 20:05











                • @Jon Bentley, hm... I'll have a look tomorrow and see how I can make this clear.

                  – Robert Riedl
                  Feb 15 at 20:19











                • Sure. And just to elaborate on my comment a little, I'm contrasting this approach with doing a alias meh='ssh admin@meh.example.com -p 1234 -i ~/.ssh/id_rsa' which would achieve the same thing. The benefit I am thinking of of using the config file is that you can enforce the IdentitiesOnly yes option. Also that it feels more "correct" to store your SSH hosts in config rather than in some bash alias.

                  – Jon Bentley
                  Feb 15 at 20:25



















                I think autocomplete for ssh-config 'just works' on ubuntu, and has worked as far as I can remember, the only place where I know it doesn't work out-of-the-box is MacOS

                – Pelle
                Feb 15 at 14:37





                I think autocomplete for ssh-config 'just works' on ubuntu, and has worked as far as I can remember, the only place where I know it doesn't work out-of-the-box is MacOS

                – Pelle
                Feb 15 at 14:37













                @Pelle, yes that's true! I better rephrase that... But you have to type out the whole of ssh plus the blank and at least the first character.. which is so much work if you have to do it often.. and as sysadmin you should be lazy ;)

                – Robert Riedl
                Feb 15 at 14:42





                @Pelle, yes that's true! I better rephrase that... But you have to type out the whole of ssh plus the blank and at least the first character.. which is so much work if you have to do it often.. and as sysadmin you should be lazy ;)

                – Robert Riedl
                Feb 15 at 14:42













                It's not clear from your answer what the benefit of combining the two approaches is, over just using the bash alias (of course I agree there is a benefit).

                – Jon Bentley
                Feb 15 at 20:05





                It's not clear from your answer what the benefit of combining the two approaches is, over just using the bash alias (of course I agree there is a benefit).

                – Jon Bentley
                Feb 15 at 20:05













                @Jon Bentley, hm... I'll have a look tomorrow and see how I can make this clear.

                – Robert Riedl
                Feb 15 at 20:19





                @Jon Bentley, hm... I'll have a look tomorrow and see how I can make this clear.

                – Robert Riedl
                Feb 15 at 20:19













                Sure. And just to elaborate on my comment a little, I'm contrasting this approach with doing a alias meh='ssh admin@meh.example.com -p 1234 -i ~/.ssh/id_rsa' which would achieve the same thing. The benefit I am thinking of of using the config file is that you can enforce the IdentitiesOnly yes option. Also that it feels more "correct" to store your SSH hosts in config rather than in some bash alias.

                – Jon Bentley
                Feb 15 at 20:25







                Sure. And just to elaborate on my comment a little, I'm contrasting this approach with doing a alias meh='ssh admin@meh.example.com -p 1234 -i ~/.ssh/id_rsa' which would achieve the same thing. The benefit I am thinking of of using the config file is that you can enforce the IdentitiesOnly yes option. Also that it feels more "correct" to store your SSH hosts in config rather than in some bash alias.

                – Jon Bentley
                Feb 15 at 20:25













                5














                Yet another option is to use the history features of the shell. You can Ctrl-r in bash and type a unique substring of the last time you ssh'ed to that place. If there's no unique substring, you can just use whatever qualifies best as a rare substring and browse through the history entries by repeatedly pressing Ctr-r until you get to it. For example, you might type Ctrl-r and "monkeys" or "codemonkeys" or "odemon" or "kong" and get



                ssh kong@codemonkeys.some-server.com


                from the last, and hopefully only time you typed that whole.



                With the history features of the shell, there's really no reason to type any long command more than once.






                share|improve this answer






























                  5














                  Yet another option is to use the history features of the shell. You can Ctrl-r in bash and type a unique substring of the last time you ssh'ed to that place. If there's no unique substring, you can just use whatever qualifies best as a rare substring and browse through the history entries by repeatedly pressing Ctr-r until you get to it. For example, you might type Ctrl-r and "monkeys" or "codemonkeys" or "odemon" or "kong" and get



                  ssh kong@codemonkeys.some-server.com


                  from the last, and hopefully only time you typed that whole.



                  With the history features of the shell, there's really no reason to type any long command more than once.






                  share|improve this answer




























                    5












                    5








                    5







                    Yet another option is to use the history features of the shell. You can Ctrl-r in bash and type a unique substring of the last time you ssh'ed to that place. If there's no unique substring, you can just use whatever qualifies best as a rare substring and browse through the history entries by repeatedly pressing Ctr-r until you get to it. For example, you might type Ctrl-r and "monkeys" or "codemonkeys" or "odemon" or "kong" and get



                    ssh kong@codemonkeys.some-server.com


                    from the last, and hopefully only time you typed that whole.



                    With the history features of the shell, there's really no reason to type any long command more than once.






                    share|improve this answer















                    Yet another option is to use the history features of the shell. You can Ctrl-r in bash and type a unique substring of the last time you ssh'ed to that place. If there's no unique substring, you can just use whatever qualifies best as a rare substring and browse through the history entries by repeatedly pressing Ctr-r until you get to it. For example, you might type Ctrl-r and "monkeys" or "codemonkeys" or "odemon" or "kong" and get



                    ssh kong@codemonkeys.some-server.com


                    from the last, and hopefully only time you typed that whole.



                    With the history features of the shell, there's really no reason to type any long command more than once.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Feb 14 at 18:02

























                    answered Feb 14 at 17:54









                    JoLJoL

                    1,13437




                    1,13437























                        3














                        I usually just create a .sh which contains a ssh command. For example:



                        # file name: mywebsite-live.sh
                        ssh username@123.123.123.123 # or whatever the domain is.


                        And then to run it I simply do ./mywebsite-live.sh



                        I realise that it's probably a pretty crappy solution but it works for me and the hope is that it might work for someone else too.






                        share|improve this answer




























                          3














                          I usually just create a .sh which contains a ssh command. For example:



                          # file name: mywebsite-live.sh
                          ssh username@123.123.123.123 # or whatever the domain is.


                          And then to run it I simply do ./mywebsite-live.sh



                          I realise that it's probably a pretty crappy solution but it works for me and the hope is that it might work for someone else too.






                          share|improve this answer


























                            3












                            3








                            3







                            I usually just create a .sh which contains a ssh command. For example:



                            # file name: mywebsite-live.sh
                            ssh username@123.123.123.123 # or whatever the domain is.


                            And then to run it I simply do ./mywebsite-live.sh



                            I realise that it's probably a pretty crappy solution but it works for me and the hope is that it might work for someone else too.






                            share|improve this answer













                            I usually just create a .sh which contains a ssh command. For example:



                            # file name: mywebsite-live.sh
                            ssh username@123.123.123.123 # or whatever the domain is.


                            And then to run it I simply do ./mywebsite-live.sh



                            I realise that it's probably a pretty crappy solution but it works for me and the hope is that it might work for someone else too.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Feb 14 at 12:54









                            PrintlnParamsPrintlnParams

                            391




                            391















                                Popular posts from this blog

                                How to change which sound is reproduced for terminal bell?

                                Can I use Tabulator js library in my java Spring + Thymeleaf project?

                                Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents