As a developer or dev-ops you need to access many servers or hosts via ssh, usually you are doing this like the following:
ssh user@[IP/Domain] -p port -i PATH_TO_PRIVATE_KEY
There is a very easier way to do it like the following:
- Open your ssh config file or create it if it doesn’t exist at: ~/.ssh/config
- Add the following:
Host YOU_CAN_CHOOSE_ANY_NAME_YOU_WANT
Hostname 1.1.1.1
User root
Port 22
IdentityFile ~/.ssh/private_key
- You can remove IdentityFile or Port if it is not needed.
- Save the file.
- Now you can connect via ssh using the following command.
ssh MY_NEW_HOST_NAME