I'm a Linux novice trying out a lot of bash scripting lately, as it is so very addictive.
Lately I have been setting up one of my boxes remotely and have been hardening it as much as possible. Please allow me to explain the scenario, as it does tend to become a little complicated (at least for me).
The target box is a debian system. I have implemented the following:
- portknocking (to open up ssh port)
- I use keys to connect instead of password
- I also use OTPW (one time passwords) in addition (its a 2 factor authentication).
So it must satisfy both requirements in order to allow me to login. Up to this point it all works great as expected. At some point when I need to scp some files or I need to login multiple times a day, it gets a bit annoying with the OTPW, so I created a small shell script where I would enter the challenge number and it will grep my pass file and provide me with the one-time-pass to use for this login. So i can just copy/paste it. This part also works fine so far.
Now, I want to create a shell script... that will do the initial ssh connection and wait for the response at the login which looks like this:
So it asks me for my one time password for number 067
I want the script to automatically read the 067 and place it in a variable, so that I can use that variable to calculate my pass needed (i have the part already working where i can enter the number and get a pass from it), and after this process is done to send the password for 067 to the server to complete the login process.
The script that I have made where I can enter manually the number 067 and it greps and cuts the results to my liking (which works) is:
So in this script, I enter the number given to me by the challenge from the SSH login, and it returns for me the one-time-pass.
I now need a script that will by itself read the challenge, and automatically do similar/same steps as above and complete the login automatically.
What I have so far is:
There is alot of stuff commented out or missing in this script, but please ignore those, as it is nowhere near complete.
NOTE: Just to be clear, i only need help with the part of getting the 067 response put in to a variable, from there I should be able to tackle the rest on my own.
Any help would be appreciated
Cheers,
instro
Last edited by rbatte1; 06-12-2015 at 08:07 AM..
Reason: Fixed typos. RBATTE1 converted text to numbered list
The problem is you want to borrow the tty to get data, but then continue to use it interactively. You'll need a middle-man.
expect is a tcl program that can script interactive programs, and I assume give control back to the terminal once the login is done. I am sorry I can't further assist with it's language though.
How do a user login with full user-environment preset to Bash shell then automatically do path modification with few script codes, either on command-line or put it in a script file.
what i tried:
bash --login -c PATH="/ANewPath:${PATH}"
bash --login -c 'PATH="/ANewPath:${PATH}"; export PATH'... (2 Replies)
Greetings, guys. I'm not much of a programmer forgive me for being a noob, because of someone leaving, I was put in an IT spot where I have to figure out a few things. Being new to Linux and programming has been a challenge.
My boss has asked me to create an automated script to connect to a 3rd... (7 Replies)
Hi
I have a script at Server B. I want to run it from server A via another script. I tried the following command. ssh mss@247.123.456.123 "sh pm10.sh"
It's getting login automatically, but while running the script through error like "reppar: command not found" where reppar is an application... (4 Replies)
Hi All,
I need information regarding how to automate the pbrun process in script in Linux.
Example sample script below,
#!bin/sh
/usr/xyz/pbrun testusr -password testpwd
testusr is username for pbrun and testpwd is password for pbrun.
Im not sure if it is correct way to invoke pbrun in... (2 Replies)
Hi Guys!
I am trying to write a shell script for automated ssh. vairable user and passwd have initialized correctly, but when I use the following it still prompting me for the password.
#!/usr/bin/bash
user='root@10.14.76.225'
passwd='admin'
ssh $user
$passwd
uptime
exit
I... (3 Replies)
Hi,
Can anyone pls help me to automate login to cvs. I basically want to login to cvs and update a file.
the script always gets to the login and returns the prompt for a password.
Is there any way to send the password in the script itself.
Here is the script:
#!/bin/ksh... (0 Replies)
Ok, there's been a good number of posts about this, but here goes. I want a script to log in to a system via ssh without using keys.
This will be used to log in to Cisco IOS devices.
I have tried the following, but could not get it to work:
SSH login expect shell script to supply username and... (1 Reply)
hello
anyone have done ssh login script without "expect"
(automatic login from host A / user b to Host B / user b without enter any passwords)?
cheers (2 Replies)
hi.
I need a bash script which can login to an other mashin via SSH and then run some commands and then return the result to my mashine.
I dont know where to begin, I think first I will need a ssh connection, dont know how to make it,
then , do I need a ftp connection between the 2 mashins to... (5 Replies)