LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-26-2014, 09:20 AM   #1
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Rep: Reputation: Disabled
how can I run remotley my test script without password?


Hi all,

how can I run remotely my test script without password?


lets say user named "user" at host2 that has script located on /tmp/test.sh

I like to run that script on host1 using this:

ssh user@host2 'bash /tmp/test.sh'

the script actually runs but it ask me a password to login on host2. Is there a shortcut way so I would only just run the script next time without putting the password to host2?
 
Old 06-26-2014, 09:30 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
private key authentication:http://linuxproblem.org/art_9.html
 
1 members found this post helpful.
Old 06-26-2014, 09:32 AM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,116

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
Use google to search for 'passwordless ssh' for your distribution.

But typically it comes down to using ssh-keygen and sending up the key.

Code:
ssh-keygen -t rsa
ssh-copy-id user@host2
 
2 members found this post helpful.
Old 06-26-2014, 09:33 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 2,305

Rep: Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816Reputation: 816
http://centos.tips/ssh_nopw/
 
1 members found this post helpful.
Old 06-26-2014, 09:38 AM   #5
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
thanks, seems like all of you has same idea to to solve my problem. I'll try it

Last edited by apss_evaluator; 06-26-2014 at 09:39 AM.
 
Old 06-26-2014, 01:49 PM   #6
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by apss_evaluator View Post
thanks, seems like all of you has same idea to to solve my problem. I'll try it
different scenario this time

script from host2 is owned by user2 and located on /opt/user2/bin/test.sh

but 1st for me to able to run the script from host2 I need to be logged as "user" then sudo su to "user2"
running this command in host2 as user= sudo su - user2


question is I want to run the script from host1 using "user"

I tried this = ssh user@host2 'sudo su - user2 -c /opt/user2/bin/test.sh'

it asked the password for user2 but it gives me this error = sudo: sorry, you must have a tty to run sudo

Last edited by apss_evaluator; 06-27-2014 at 04:35 AM.
 
Old 06-26-2014, 02:00 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,116

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
You can comment out the 'requiretty' line in your sudoers file, if you'd like to not require a tty.
 
1 members found this post helpful.
Old 06-26-2014, 02:06 PM   #8
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by szboardstretcher View Post
You can comment out the 'requiretty' line in your sudoers file, if you'd like to not require a tty.
thanks, but does commenting on it would affect on the sudoers rule?

actually I'm not yet fully familiar with it
 
Old 06-26-2014, 02:18 PM   #9
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,116

Rep: Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530Reputation: 1530
vim /etc/sudoers

Code:
# add this
Defaults:user2 !requiretty
That will remove the requirement for a tty for that user -- the error you mentioned.
 
1 members found this post helpful.
Old 06-26-2014, 10:53 PM   #10
Doug G
Member
 
Registered: Jul 2013
Posts: 658

Rep: Reputation: Disabled
ssh -t might work for you, it works for me to use ssh to sudo a remote script that calls another remote script.
 
1 members found this post helpful.
Old 06-27-2014, 04:13 AM   #11
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Doug G View Post
ssh -t might work for you, it works for me to use ssh to sudo a remote script that calls another remote script.
thanks, I'll try it
 
Old 06-27-2014, 04:31 AM   #12
apss_evaluator
Member
 
Registered: Mar 2012
Posts: 115

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by apss_evaluator View Post
thanks, I'll try it
I tried it, but looks like it still did not execute the script the way I expected


#ssh user@host2 '/opt/user2/bin/test.sh'


ls: cannot open directory /opt/user2/packages: Permission denied
/opt/user2/bin/test.sh: line 133: kill: (23125) - Operation not permitted
/opt/user2/bin/test.sh: line 136: kill: (23125) - Operation not permitted
ls: cannot access /opt/user2/pkg/jboss-/server/default/deploy: No such file or directory

Last edited by apss_evaluator; 06-27-2014 at 04:36 AM.
 
Old 06-27-2014, 07:58 AM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,332
Blog Entries: 55

Rep: Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533
Apart from 0) not using 'ls' in scripts if you are going to parse the output, 1) testing before you do something and 2) using a completely different "user" account ("user != "user2") to execute your script "ssh user@host2" I think you should cut this short by posting the actual full contents of "/opt/user2/bin/test.sh", what it should achieve, determine the owner of the process with PID 23125 and check why (sub)directory ownership doesn't match the (presumed) "user2" account.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] run script as root without password jibtga Linux - Newbie 10 06-14-2012 09:31 AM
Run a script without password ! shipon_97 AIX 1 12-29-2009 07:53 AM
Test if a script has already been run ColInvictus Linux - Newbie 7 10-05-2009 10:03 PM
In a perl script, how to test if user has sudo execute w/o password ? etomato Linux - Newbie 6 11-19-2008 11:18 PM
if you run perl, could you test this script: 2007fld Programming 1 07-20-2007 06:21 PM


All times are GMT -5. The time now is 06:58 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration