Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-11-2011, 08:56 AM
|
#1
|
Member
Registered: Nov 2010
Posts: 87
Rep:
|
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.
|
|
|
01-11-2011, 10:33 AM
|
#2
|
LQ Guru
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 6,129
|
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?
|
|
|
01-11-2011, 11:13 AM
|
#3
|
LQ Newbie
Registered: Dec 2008
Location: Yukon, Canada
Distribution: Debian/Ubuntu
Posts: 20
Rep:
|
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...
|
|
|
01-11-2011, 12:04 PM
|
#4
|
Member
Registered: Nov 2010
Posts: 87
Original Poster
Rep:
|
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.
|
|
|
01-11-2011, 12:22 PM
|
#5
|
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: 
|
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.
|
|
|
01-12-2011, 11:35 AM
|
#6
|
Member
Registered: Nov 2010
Posts: 87
Original Poster
Rep:
|
Thanx vorbote!!
can you please explain it further. how this process goes.
please explain this with an example/set of commands.
|
|
|
01-12-2011, 01:33 PM
|
#7
|
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: 
|
Quote:
Originally Posted by aggrishabh
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.
|
|
|
All times are GMT -5. The time now is 12:49 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|