Operating System - HP-UX
1832988 Members
2680 Online
110048 Solutions
New Discussion

SU command in non interactive mode

 
Guy_34
New Member

SU command in non interactive mode

Can i run the SU command in a non interactive mode. What i want to do is to pass the username and the password as commandline or batch parameters. Please let me if its possible and how to pass them. A sample file will be appreciated.

Thanks,
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: SU command in non interactive mode

No and this would be a huge security risk if you could. Only when you are running as root will su not prompt for a password. A good way to do this is via the sudo command. A less good way would be to create a setuid c program that exec's your script.

You can get sudo here:
http://hpux.connect.org.uk/hppd/hpux/Sysadmin/sudo-1.6.7p5/
If it ain't broke, I can fix that.
Michael Tully
Honored Contributor

Re: SU command in non interactive mode

You could also wrap this up in an expect script. See the attached example of providing a password without user interaction.

Anyone for a Mutiny ?
Michael Tully
Honored Contributor

Re: SU command in non interactive mode

What I should have also mentioned is that there is a security risk associated with this, as rightly pointed out already by Clay.
Anyone for a Mutiny ?
Mauro Gatti
Valued Contributor

Re: SU command in non interactive mode

You can evaluate to use "ssh -l username host command" being sure to exchange before and register public user key in authorized_keys file.

RGDS


Mauro
Ubi maior, minor cessat!
Victor Fridyev
Honored Contributor

Re: SU command in non interactive mode

Hi,

The following workaround is also possible:
Instead of running su command you can run remsh. In this case you permit to user1 from computer srvrn (own hostname) to login as user2 without an authentication, i.e. in ~user2/.rhosts you add
srvrn user1.

in this case you run as user1 on srvrn
remsh srvrn -l user2 needed_script
Entities are not to be multiplied beyond necessity - RTFM