LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-11-2011, 08:56 AM   #1
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Rep: Reputation: 1
password less sudo su - abc


Hi All,

I need to write a script in which i have to execute some commands after
sudo su - abc
command. Above command ask for password which i need to give through script.

please help me in this. there is no issue if the password is in plain text. It will be great if we can provide encrypted password.

Note: we cant do any changes in visudo file.
 
Old 01-11-2011, 10:33 AM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,674

Rep: Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712Reputation: 2712
passwordless

I assume that when you say "we cant do any changes in visudo file" that you mean that you cannot use visudo to make changes to the sudoers file.

That is a serious restriction, since the only supported way to bypass the password requirement is by configuration of that particular command to use the NOPASS: option in the sudoers file.
Any other means is an attempt to bypass server security and would certainly cause me to take rather abrupt action if I were the System Administrator for that server.

1. Can you get help from someone who CAN make changes to the sudoers file?
2. If not, are you approved to use another technique that does not involve sudo?

I have to wonder why someone who is not authorized to configure sudo would be required to modify sudo behavior. Is there something else involved here that we should understand?
 
Old 01-11-2011, 11:13 AM   #3
bobloblian
LQ Newbie
 
Registered: Dec 2008
Location: Yukon, Canada
Distribution: Debian/Ubuntu
Posts: 20

Rep: Reputation: 1
I believe sudo has an option -S, so you can do something like:
echo PASSWORD | sudo -S <command>
I don't know if I have the syntax right, but it is something like that...
 
Old 01-11-2011, 12:04 PM   #4
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Original Poster
Rep: Reputation: 1
Thanks for all your Input!!

actually the scenario is we have to do some regular task which can be done only after login with that user for this we need to fire command sudo su - abc. The owner of this server is someone else. to help myself i am writing a script to automate this task.
 
Old 01-11-2011, 12:22 PM   #5
vorbote
Member
 
Registered: Aug 2009
Location: 2,625 m of paranoia above sea level
Distribution: Arch Linux, Debian GNU/Linux, Fedora, Void Linux, FreeBSD, OpenBSD and Win10
Posts: 77

Rep: Reputation: Disabled
Drop the sudo and su, you don't need both! Just read the man pages and you'll see that you can change the effective user with either. "sudo su -" us a construct used in cases where the root password is non-existent in practice such as with Ubuntu Linux.

For your purposes, your best bet is sudo, see the -A option. But, you can do much better using a little hack with SSH if the box has installed the server. Create a keypair without a password *locally*, upload to the admin account, copy the public part to the target user account. Set up a cron job that runs an rsh-like job in the target account using ssh. Your done.

Last edited by vorbote; 01-11-2011 at 12:25 PM.
 
Old 01-12-2011, 11:35 AM   #6
aggrishabh
Member
 
Registered: Nov 2010
Posts: 87

Original Poster
Rep: Reputation: 1
Thanx vorbote!!

can you please explain it further. how this process goes.

please explain this with an example/set of commands.
 
Old 01-12-2011, 01:33 PM   #7
vorbote
Member
 
Registered: Aug 2009
Location: 2,625 m of paranoia above sea level
Distribution: Arch Linux, Debian GNU/Linux, Fedora, Void Linux, FreeBSD, OpenBSD and Win10
Posts: 77

Rep: Reputation: Disabled
Quote:
Originally Posted by aggrishabh View Post
Thanx vorbote!!

can you please explain it further. how this process goes.

please explain this with an example/set of commands.
With sudo, this is a matter of using the -A option and find a way to feed it the password automagically: "sudo -A -u <target_user> <command>. You set the ASK_PASS environment variable in the source account to a small program that automatically dumps the password to standard output when executed, see sudo(1) for a better explanation. In any case, it is as insecure are you can get.

With ssh, it is almost as if using rsh, but secure. You create a paswordless keypair, copy the public key to the target user .ssh directory and there you have it, you can do "ssh target_user@localhost" and it logs you in automatically without a password. Then you create a crontab entry for your source user with "crontab -e" (check crontab(5) for format details) with a command of the form "ssh target_user@localhost <command to be executed>" and that's it.

A good example of how this ssh setup works is the shell access service at SourceForge. See <http://sourceforge.net/apps/trac/sourceforge/wiki/Shell service> for a description.
 
  


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
Setup Apache so Webmin can be accessed like abc.com/webmin instead of abc.com:10000 rtoney5 Linux - Software 6 04-08-2010 12:33 PM
my sudo password is not the root password newbiesforever Linux - General 7 01-02-2010 09:59 PM
Sudo password kapilbajpai88 Linux - Newbie 9 11-06-2009 03:15 AM
Compare string (capitol letters) abc to ABC Willy Fog Linux - Newbie 4 09-17-2009 11:36 AM
How to set linux environment variable like abc.abc (With DOT in the string) super_hill Linux - General 1 12-03-2008 07:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:46 PM.

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