LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-02-2015, 06:55 AM   #1
asteroid4u
Member
 
Registered: Jun 2015
Posts: 58

Rep: Reputation: Disabled
ssh login with password Pass


Hi Gurus,

Thanks a lot who are trying to help me

Below are the requirement

I have 20 Machines in site A
I have 1 Machine (i will call it machine1) in site B

In site A we have around 40 Users

users in site A has to be connect to site B machine1 (using always user1) in shell script from all 20 Machines from site A.

We can do password less authentication but my case 20 Machines and 40 different users

expect is the right way ? but I want to run shell script also

How to done this?
 
Old 12-02-2015, 07:46 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by asteroidmilky@gmail.com View Post
Hi Gurus,
Thanks a lot who are trying to help me

Below are the requirement

I have 20 Machines in site A
I have 1 Machine (i will call it machine1) in site B

In site A we have around 40 Users users in site A has to be connect to site B machine1 (using always user1) in shell script from all 20 Machines from site A. We can do password less authentication but my case 20 Machines and 40 different users

expect is the right way ? but I want to run shell script also How to done this?
You do this by writing a shell script and/or an expect script. Can you post what you've done/tried so far? See the "Question Guidelines" link in my posting signature...we are happy to help, but we aren't going to write scripts for you.

And your 'requirement' makes little sense. You say you have 40 users, who need to connect to another machine...all with the same user id, through a shell script. That's fine...so what's the problem? If they ALWAYS log in with "user1", then do your SSH keyswap, and tell the shell script to use it. Otherwise, just keyswap all 40 of your users from their workstations to machine1, and have your remote shell script do something like "sudo su - user1", allowing each user to log in as themselves, and assume the role of user1 at login. There is AMPLE documentation on how to write expect scripts you can easily find with a Google search. Read the "Question Guidelines" link in my posting signature.

Please explain what you're trying to accomplish, and show us what you've done so far. You may also want to message user Sagar666 on this site...I believe they have some experience with SSH. But I believe that's your other user name, isn't it?
http://www.linuxquestions.org/questi...xi-4175552911/

http://www.linuxquestions.org/questi...er-4175530835/
http://www.linuxquestions.org/questi...cp-4175532223/

Last edited by TB0ne; 12-02-2015 at 07:54 AM.
 
Old 12-02-2015, 08:46 AM   #3
624867243@qq.com
Member
 
Registered: Nov 2015
Location: ShenZhen
Posts: 33
Blog Entries: 1

Rep: Reputation: Disabled
you can use sshpass,salt or ansible.
 
Old 12-03-2015, 12:40 AM   #4
asteroid4u
Member
 
Registered: Jun 2015
Posts: 58

Original Poster
Rep: Reputation: Disabled
Hi TB one,

Below is the script its just example to show where i struck

#get current directory
arg3=`pwd`
#directory path defined
path=/home/user1/a5/gen/rel/src
# Connect to remote machine and pass script arguments
sshpass -p 'abc' ssh -o StrictHostKeyChecking=no user1@cin $arg1 $arg2 $arg3
#get total fields of directory
T_field=`echo "$path" | awk -F"/" "{ print NF }"`
a=1
b=3
#get fourth and second field number only
Fourth="$((T_field - a))"
Second="$((T_field - b))"
#get field names
F_field=`echo "$path" | cut -d'/' -f$Fourth`
S_field=`echo "$path" | cut -d'/' -f$Second`
echo "$F_field"
echo "$S_field"
echo "arg1"
#get only directories name and send to output
ls -d */ > /home/lint/
#go to each directory and do some commands
while read line
do
cd line
hg pull; hp update
cd ..
done < output

In above script its just login to remote machine and not passing arguments and not running further script. Here I need help

Last edited by asteroid4u; 12-03-2015 at 12:41 AM.
 
Old 12-03-2015, 12:46 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
1. please use code tags https://www.linuxquestions.org/quest...do=bbcode#code when posting your code and indent it properly for eg while loops etc
2. You call sshpass with 3 "args", but only one (arg3) is set
 
Old 12-03-2015, 02:04 AM   #6
asteroid4u
Member
 
Registered: Jun 2015
Posts: 58

Original Poster
Rep: Reputation: Disabled
Hi Chrishm01

Sorry I missed it actually user gives two arguments.

Below is the script its just example to show where i struck
[code]
#!/bin/sh
#get current directory
arg3=`pwd`
#directory path defined
path=/home/user1/a5/gen/rel/src
# Connect to remote machine and pass script arguments
sshpass -p 'abc' ssh -o StrictHostKeyChecking=no user1@cin $1 $2 $arg3
#get total fields of directory
T_field=`echo "$path" | awk -F"/" "{ print NF }"`
a=1
b=3
#get fourth and second field number only
Fourth="$((T_field - a))"
Second="$((T_field - b))"
#get field names
F_field=`echo "$path" | cut -d'/' -f$Fourth`
S_field=`echo "$path" | cut -d'/' -f$Second`
echo "$F_field"
echo "$S_field"
echo "arg1"
#get only directories name and send to output
ls -d */ > /home/lint/
#go to each directory and do some commands
while read line
do
cd line
hg pull; hp update
cd ..
done < output
[code]
 
Old 12-03-2015, 02:34 AM   #7
asteroid4u
Member
 
Registered: Jun 2015
Posts: 58

Original Poster
Rep: Reputation: Disabled
Thanks a lot I got it. I kept rest script in remote machine
 
  


Reply

Tags
linux, passwordless, shell scripting, ssh access



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: SSH login without password using SSH keys LXer Syndicated Linux News 0 09-21-2014 01:36 AM
Remote ssh login (passwords useless), and local login (using password) linuxStudent11 Linux - Security 1 01-09-2013 01:30 PM
[SOLVED] pass password in bash script to SSH vikas027 Programming 4 01-20-2012 03:09 PM
[SOLVED] SSH login problem for additional users after password-less login setup uncle-c Linux - Newbie 3 02-10-2010 12:51 PM
Pass password with ssh command BruceC Linux - Newbie 2 05-12-2004 08:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 03:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration