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

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.


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.


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 auto-completion (after ssh[Blank]), but it's still an awful lot to type.

So let's 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 an alias:

alias m='ssh meh'

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