How to save SSH options and connections in Ubuntu? [duplicate]

You can use a per-user ssh-config file located in

~/.ssh/config

or a system-global one in

/etc/ssh/ssh_config

that stores the basic settings for each connection.

Example:

Host example_host
    User foo
    HostName example.com
    IdentityFile ~/.ssh/foo.key
    Port 23421

Having this in place, calling

ssh example_host

will open up a ssh-connection to example.com on port 23421, using the user foo and foo.key for authentication.

For an in-deep explanation, see the man page of ssh:

man ssh

Don't forget to set proper permissions on the config file:

chmod 600 ~/.ssh/config

There is ~/.ssh/config as pointed out in the manual pages for ssh. It is well described there and in man ssh_config and also many times answered on askubuntu.

TL;DR:

# to preserve connections:
ControlMaster auto
ControlPath ~/.ssh/controlmasters/%r@%h:%p
ControlPersist 20m

# to provide correct keys, users, IPs and use aliases
Host yourHost
  Hostname IPaddress
  User user1
  IdentityFile ~/.ssh/id_ecdsa

Host yourSecondHost
  Hostname IP2
  User user2
  IdentityFile ~/.ssh/id_rsa

If you don't want to write passphrases, there is ssh-agent, where you can add the keys for your session:

eval `ssh-agent`
ssh-add ~/.ssh/id_ecdsa
# insert passphrase once
ssh yourHost
# will ask only for password
# next ssh connections will not ask for