Permanently store addresses when using SSH

For SSH connections, you can create a user configuration file ~/.ssh/config and place the mappings there e.g.

Host server1
  Hostname      111.222.111.222

You can easily add other fields such as Port (for non-standard ports) and User (useful if your username on the remote system differs from that on the local system). See man ssh_config for full details.


Yes, just write them down in the file /etc/hosts. It has the following syntax:

1.2.3.4 servername additional_servername

Where:

  • 1.2.3.4 is the IP address
  • servername is the name
  • additional_servername is an optional name

After saving, you can reach the server by its name.


Of course for your particular issue you want to follow @chaos and @steeldriver advices, but in the general case, in order to "permanently store values in the terminal", you are looking to shell variables. How to set them will depend on your shell (I guess echo $SHELL will provide the relevant information).

If by "permanently" you mean "as long as I don't exit this terminal session", then you can simply use the export server1=111.222.111.222 command if you're using a bash-based shell (setenv server1 111.222.111.222 for a csh/tcsh-based shell, if I remember correctly). Then you can access your variable by prefixing it with $ : ssh root@$server1.

If by "permanently" you mean "each time I launch a new terminal", then you will need to set your variable in one of the shell init files. E.g. in $HOME/.bashrc for bash-based shells, or $HOME/.cshrc — presumably using the same syntax as mentionned in the previous paragraph. Note that you will have to source the init file (e.g. source $HOME/.bashrc or open a new shell for changes to be taken into account.

NB : Answer from memory, may require some small adjustments.