LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how can I run remotley my test script without password? (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-run-remotley-my-test-script-without-password-4175509258/)

apss_evaluator 06-26-2014 08:20 AM

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?

schneidz 06-26-2014 08:30 AM

private key authentication:http://linuxproblem.org/art_9.html

szboardstretcher 06-26-2014 08:32 AM

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


TenTenths 06-26-2014 08:33 AM

http://centos.tips/ssh_nopw/

apss_evaluator 06-26-2014 08:38 AM

thanks, seems like all of you has same idea to to solve my problem. I'll try it

apss_evaluator 06-26-2014 12:49 PM

Quote:

Originally Posted by apss_evaluator (Post 5194371)
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

szboardstretcher 06-26-2014 01:00 PM

You can comment out the 'requiretty' line in your sudoers file, if you'd like to not require a tty.

apss_evaluator 06-26-2014 01:06 PM

Quote:

Originally Posted by szboardstretcher (Post 5194515)
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

szboardstretcher 06-26-2014 01:18 PM

vim /etc/sudoers

Code:

# add this
Defaults:user2 !requiretty

That will remove the requirement for a tty for that user -- the error you mentioned.

Doug G 06-26-2014 09:53 PM

ssh -t might work for you, it works for me to use ssh to sudo a remote script that calls another remote script.

apss_evaluator 06-27-2014 03:13 AM

Quote:

Originally Posted by Doug G (Post 5194679)
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

apss_evaluator 06-27-2014 03:31 AM

Quote:

Originally Posted by apss_evaluator (Post 5194771)
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

unSpawn 06-27-2014 06:58 AM

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.


All times are GMT -5. The time now is 09:12 AM.