use this code at your own risk and only if you know what you are doing. no liability from us for the consequences. so leave us alone if things go sideways
I am regularly connecting to multiple remote systems via SSH, and as far as I am concerned I find that remembering all of the remote IPs, the non-standard ssh ports, and various command-line options difficult, annoying, and at some stage or office hour impossible. The option for creating a bash alias file would do the trick, but i guess well not cool, or in other words not the use case I have.
Step 1 located in the /home directory of the user you can find .ssh/config if not, well you have to create the config file. If you want to edit the global config use /etc/ssh/ssh_config (must be readable to all users)
sudo chmod 600 home/user/.ssh/config
The config file structure looks something like this, and it is processed from top to bottom. The SSH command from the cli processes its configuration in the following order:
- ssh command line-option
- /home/user/.ssh/config option
- /etc/ssh/ssh_config options
Keep that in mind, if you are using override commands.
Step 2 edit the file for your needs
Use Case to get connected:
ssh userNeeds@ssh.host.exymple.tld -p4422
with config file in /home/userNeeds/.ssh/config that looks something
I will just need to type this to get connected:
Pretty fly ha?
These are the Config parameters you can use. (I will not get into Wild Cards and ref exp)
HostName: IP address of the remote server
User: Name of the user, you will log in as 9999
Port: The to connect on the remote server
Protocol: The version of protocol SSH should prefer (multi Values separated by comma)
IdentityFile: Location of file that contains RSA, ECDSA, and DSA authentication Identity
ForwardX11: It allows you to forward the remote server display on your machine
Compression: You want to use compression during the remote server connection or not
ServerAliveinterval: Set a timer in seconds for the server connection and in the given time if no response is received from the server, ssh will send a message to request a response
ServerAliveCountMax: Sets the number of messages that should be sent to request a response from the server
LogLevel: Verbosity level used when logging
So a common use case config looks like something like this
Host grommuo HostName grommuo.hatesno.plan Port 2222 Forwardx11 no User tec-noP1503 IdentityFile ~/.ssh/id_rsa Protocol 2 Compression yes LogLevel Info
so to get connected tech tech guy only has to type ssh grommuo and is good go, fine thing and makes life easier.
have Fun !