0

I have a problem with my situation that i have to run a script inside another machine as root. I can only do ssh without password as oracle, so i have to write something like that:

  su - oracle -c "ssh $node /tmp/x.sh"

How can i run x.sh as root?

EDIT

[root@alz1 ~]# su - oracle
[oracle@alz1 ~]$ su
Password: 
su: incorrect password
[oracle@alz1 ~]$ 
3
  • 1
    You are root initially, change user to oracle, and then try to change back to root again? Why? Nowhere do you connect to a remote machine. Commented Mar 19, 2014 at 12:44
  • Because i can only ssh with oracle. Also i need to run my command as root Commented Mar 19, 2014 at 12:45
  • Yes, but you also need to connect to the remote box somewhere. See my new answer. Commented Mar 19, 2014 at 12:47

2 Answers 2

1

Have you tried

su - oracle -c "ssh root@$node /tmp/x.sh"
Sign up to request clarification or add additional context in comments.

8 Comments

I doesn't work because when i can only ssh to another node as oracle. When i ssh to other node with oracle, then run as root, it wants password.
If you can't ssh in as root, you need sudo access or the root password. If you have neither of those, you need to talk to the administrator of the machine you are trying to do this to.
I have root password but how can i ssh with password in script ?
It's not a good idea to store the root password in a script. Can you not ssh in to the oracle user interactively, and then run su - -c /tmp/x.sh?
Alternatively, you could set up passphrase-less keys to let your remote oracle user access the remote root user without needing to type anything. This would make the oracle user equivalent to root on the remote box, which may not be desireable.
|
0

Try this:

[root@box1]# su - oracle
[oracle@box1]$ ssh box2
[oracle@box2]$ su -

Then type the password for root at the remote box. It should then proceed as

[root@box2]# /tmp/x.sh

and you're done.

2 Comments

i can connect with putty as root to machine but not with "su -" command, that's strange. what if i get the right password, how can i set password when running from script?
You don't want the root password stored in a script. You can set up ssh to allow access without having to type anything by using keys with no passphrase. Google for "ssh passphrase-less root access" will give you some pointers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.