LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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, 08: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, 08:30 AM   #2
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

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

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
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, 08:33 AM   #4
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
http://centos.tips/ssh_nopw/
 
1 members found this post helpful.
Old 06-26-2014, 08: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 08:39 AM.
 
Old 06-26-2014, 12: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 03:35 AM.
 
Old 06-26-2014, 01:00 PM   #7
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
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, 01: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, 01:18 PM   #9
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
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, 09:53 PM   #10
Doug G
Member
 
Registered: Jul 2013
Posts: 749

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, 03: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, 03: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 03:36 AM.
 
Old 06-27-2014, 06:58 AM   #13
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:38 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
Open Source Consulting | Domain Registration