Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
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.
i need to create user with bash script. Only root have right to create user.
if my script run from root, user created.
if my script run from normal user it give error = only root may have right to create.
is there anyway to give root credential in the script ?
For example it will ask root password in the runtime. can i do it ?
You are trying something dangerous and I for my share, must refrain from giving you an advice on this. I am curious, though, as what others may have to say...
You are trying something dangerous and I for my share, must refrain from giving you an advice on this. I am curious, though, as what others may have to say...
Dear Michael,
i don't understand what do you mean by dangerous ?
i'm asking about prompt root password to create user using script. if u don't have root password then you can't create new users
Dear Michael,
i don't understand what do you mean by dangerous ?
i'm asking about prompt root password to create user using script. if u don't have root password then you can't create new users
My answer would be a repetition of what I wrote before, as long as you give no indication about your comprehension of the reasons for the complication. The root password is there on purpose and being unable to create users, you should ask why? Just to provide some variation (but I am still unable to give a different response), I treasure that there is often just 1 way to do things the right way and an arbitrary number of ways to run havoc.
Actually.., for a question like “How can I run havoc in the most efficient way” you might be blessed with a rich harvest. Unable to tell you anything else, for now. But let's wait a little. Someone else may contribute her/his five cents, her/his opinions or experience. I'll open a bottle if I learn something new from this exchange.
Just an additional question: Do you know any of the commands “sudo”, “gksudo” or “su” ? All have man-pages, if you are interested.
Last edited by Michael Uplawski; 02-13-2016 at 03:11 AM.
Reason: efficient -><- effective Kraut2English conversin
For example it will ask root password in the runtime. can i do it ?
Yes, that is what the su command is for. For example, if you put this into a script
Code:
su -c "useradd -m tobi"
and then run the script it will ask for the root password and then, if the correct password is entered, run the command specified in the quotes.
More info with
Code:
man su
If you want users to have access to certain commands that must run as root should also look at the sudo command, it allows you to exactly specify what the user is allowed to do and you don't have to give away the root password.
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 3,137
Rep:
Quote:
Originally Posted by Michael Uplawski
I understand English, but I “do not feel” it. Are you trying to be cynical?
No its just not a very good idea to have your admin password in clear text, but if you are the only person with access to your machine either phusically or remotly it's ok, depends on your set up and security really.
Do not stick your root password in plain text inside a script. You said you're new to Linux, don't start out on the wrong foot.
This is exactly what sudo was built for. Give your user permission to add other users without requiring a password using sudo. Honestly though, how often are you adding new users on your system? Why can't you just su to root before running the script?
the person using the script would need to be wheel or sudo group person depending on how that owner has his or her system set up. You might be able to limit a user or users to only having some sudo rights.
then calls for that persons password to be entered then it he or she will have sudo permissions for the time limit allowed as if they where doing sudo [command] off the cli
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.