Automate your SSH Login to Remote Servers (2024)

When I started working as a data developer and a data scientist in a publishing company, I began receiving multiple login credentials to remote servers. It was a hassle to search and keep track of these credentials, especially when I have to switch servers. So, I had to find a way to automate my logins.

There are few steps you have to follow in order to automate your SSH login.

  1. Create an SSH key without Passphrase
  2. Copy SSH key to the target server
  3. Verification of copied SSH key in the remote server
  4. Create bash aliases to easily remember the server domains or use SSH Config

No Passphrase SSH Key

There are other ways to automate your login to remote server such as via EXPECT. However, this exposes your password in your script and it defeats the purpose of SSH which is using ssh keys. Aside from this, expect is not available on windows’ git bash. Hence, I had chosen the SSH key login without passphrase.

Create an SSH key and leave the passphrase blank by hitting ENTER twice.

$ ssh-keygen -t rsa -b 2048
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa.
Your public key has been saved in /home/username/.ssh/id_rsa.pub.

The default SSH key will be saved at /home/username/.ssh/id_rsa for private key and /home/username/.ssh/id_rsa.pub for public key.

See Also
Windows

Copying SSH key to the Remote Server

Copy your SSH key to your target server and supply your password by the following command;

$ ssh-copy-id username@server
server password:

Verify the Copied SSH key in the Remote Server

You have to verify that your copied SSH key is in the remote server by logging to it using the conventional SSH command and making sure that there are no extra keys in place. This time, this should not ask for a password.

$ ssh username@server
$ cat .ssh/authorized_keys

Creating Bash Aliases or Create an SSH Config

It is not much of a hassle if your remote server has a domain name that you can easily remember. If you are given with IP addresses, you have to remember them or create shortcut commands like aliases or via SSH config.

  1. To create bash aliases in your .bash_profile, open/create it with your favorite text editor. I use vim.
$ vi .bash_profile

Inside the vim editor, insert the alias;

alias datawarehouse='ssh username@server'

In the line above, ‘datawarehouse’ is the shortcut command line to replace my SSH login to my remote server.

Save and exit from the vim editor.

This time, you can easily type,

$ datawarehouse

You will automatically be connected to your server.

2. Another option is to create an SSH config.

Create a config file inside the .ssh folder

$ vi ~/.ssh/config

Inside the config file, write the following lines;

Host datawarehouse
HostName targetserver
User username
IdentityFile ~/.ssh/id_rsa

Save and exit from the vim editor. Just like the first method, you can just type in

$ ssh datawarehouse

In my case, I chose the alias method. I like to create shortcuts in one place.

Conclusion

Logging in to remote servers can be a hassle-free. This can be accomplished with few steps and a bit of familiarity with Linux commands.

In my next story, I pushed an extra step by automating my access to a Jupyterlab which is running in the remote server. If you are interested in this topic, come visit this story at (still in progress.. 😄).

References:

  1. SSH Key without Paraphrase
  2. How to create SSH Shortcut
Automate your SSH Login to Remote Servers (2024)
Top Articles
How to Get a US Phone Number in Minutes
5 Best Practices for Ethical Data Sourcing in the Age of Big Data | Sunscrapers
Bj 사슴이 분수
Tabc On The Fly Final Exam Answers
The Definitive Great Buildings Guide - Forge Of Empires Tips
Math Playground Protractor
Health Benefits of Guava
Tribune Seymour
2021 Tesla Model 3 Standard Range Pl electric for sale - Portland, OR - craigslist
Strange World Showtimes Near Amc Braintree 10
Https E24 Ultipro Com
Colts seventh rotation of thin secondary raises concerns on roster evaluation
Sand Castle Parents Guide
104 Whiley Road Lancaster Ohio
Echat Fr Review Pc Retailer In Qatar Prestige Pc Providers – Alpha Marine Group
Craiglist Tulsa Ok
Check From Po Box 1111 Charlotte Nc 28201
Rams vs. Lions highlights: Detroit defeats Los Angeles 26-20 in overtime thriller
NHS England » Winter and H2 priorities
Khiara Keating: Manchester City and England goalkeeper convinced WSL silverware is on the horizon
Praew Phat
Where to Find Scavs in Customs in Escape from Tarkov
Army Oubs
Jang Urdu Today
Music Go Round Music Store
Amortization Calculator
Directions To Cvs Pharmacy
Jeff Nippard Push Pull Program Pdf
Avatar: The Way Of Water Showtimes Near Maya Pittsburg Cinemas
Kitchen Exhaust Cleaning Companies Clearwater
The Collective - Upscale Downtown Milwaukee Hair Salon
How do you get noble pursuit?
Toonkor211
91 Octane Gas Prices Near Me
Miss America Voy Board
The Venus Flytrap: A Complete Care Guide
Bee And Willow Bar Cart
Spinning Gold Showtimes Near Emagine Birch Run
The 50 Best Albums of 2023
Priscilla 2023 Showtimes Near Consolidated Theatres Ward With Titan Luxe
When His Eyes Opened Chapter 2048
ENDOCRINOLOGY-PSR in Lewes, DE for Beebe Healthcare
Top 40 Minecraft mods to enhance your gaming experience
UT Announces Physician Assistant Medicine Program
'The Nun II' Ending Explained: Does the Immortal Valak Die This Time?
Flappy Bird Cool Math Games
Sams Gas Price San Angelo
Evil Dead Rise - Everything You Need To Know
The Plug Las Vegas Dispensary
Greg Steube Height
Electric Toothbrush Feature Crossword
Helpers Needed At Once Bug Fables
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 6819

Rating: 4.6 / 5 (56 voted)

Reviews: 95% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.