Automate your SSH logins with this .bat script for your private network.

rahulnegi

rahul negi

Posted on February 10, 2022

Automate your SSH logins with this .bat script for your private network.

If you're work requires a lot of interactions with private servers, this might come handy.

A simple bash script to automate your login process, really handful for backend-devs or Dev-Ops engineers.

Let's get into it 

Requirement :

putty.exe
"PuTTY" is open source software that is available with source code and is developed and supported by a group of volunteers. You can download PuTTY here].

I'm presenting scripts in 3 ways, use what suits your need best. All these scripts are available here.

Three ways

1. Single server login

This is the best method if you have mostly or only used one server, this is just one click away method.



@echo off
@REM Use this if you have single server to login only, provide your sysyem address to puty.exe below.

@REM Provide your system's address to the putty.exe here
set putty="C:\Program Files\PuTTY\putty.exe

@REM Provide your username@address here
set id=eclairs@192.xxx.xx.174

@REM Provide your password here
set password=passwrd@123

%putty% -pw %password% %id%

@echo 


Enter fullscreen mode Exit fullscreen mode

2. Enter the last three digits to your address. 

This method is helpful if you have multiple machine in same network, you can just enter last three digits of the address.



@echo off
@REM Enter last three number of your server's IP address only to login.

@REM Provide your system's address to the putty.exe here
set putty="C:\Program Files\PuTTY\putty.exe

@REM Provide your username@address here
set id=eclairs@192.xxx.xx.174

@REM Provide your password here
set password=passwrd@123

set /p id="Enter the suffix of IP Address you want to login: "
%putty% -pw %password% %id%

@echo 


Enter fullscreen mode Exit fullscreen mode

3. Just enter a number .

This is the best method if you have multiple logins, you can just create a hash-map type relation.

Example:

Automate ssh logins for your private network



@echo off
@REM Provide your username@address here
set id1=hello@192.168.xx.145
set id2=candy@192.xxx.xxx.173
set id3=eclairs@192.xxx.xx.174

@REM Provide your password here
set password1=passwrd@123
set password2=mypassword@123
set password3=mypassword@123

echo 1 : %id1%
echo 2 : %id2%
echo 3 : %id3%

set /p id="Enter Number to the Address you want to login: "

@REM Provide your system's address to the putty.exe here
set putty="C:\Program Files\PuTTY\putty.exe"

if %id%==1 %putty% -pw %password1% %id1%
if %id%==2 %putty% -pw %password2% %id2%
if %id%==3 %putty% -pw %password3% %id3%

@echo


Enter fullscreen mode Exit fullscreen mode

That's it for now, though I want to mention one important thing which is, 
If you're desktop has multiple users, it is advisable to not store your password in the script instead use this to take input manually.

set /p password="Enter password: "



@echo off

@REM Provide your system's address to the putty.exe here 
set putty="C:\Program Files\PuTTY\putty.exe

@REM Provide your username@address here
set id=eclairs@192.xxx.xx.174

set /p password="Enter password: " 
%putty% -pw %password% %id%

@echo 


Enter fullscreen mode Exit fullscreen mode

I know it kills the half the fun of automation but still security is must.

Open to feedback and suggestions.
Thanks :') for reading.

💖 💪 🙅 🚩
rahulnegi
rahul negi

Posted on February 10, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related