can i give root credential in the script ?
Hi i'm new in linux.
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...
|
Quote:
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 |
Quote:
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. |
You can do
Code:
echo "myadminpassword" | sudo -S /path/to/script |
Quote:
|
Quote:
Code:
su -c "useradd -m tobi" More info with Code:
man su |
Quote:
|
Safer to give script "user" permission via visudo to the adduser|useradd utility.
|
sudo -v
|
Hi,
You can have something like this in your script if only you will be using it, but use it at your own risk. #Runs the command sudo cmd_name #Enters root password and does not display output echo "password" > /dev/null This will run the command with sudo and then prompt for a password which will be entered with the second command echo. |
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? |
You could add the user you are using to the wheel group which will give the user root privileges.
|
Quote:
|
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.
here is a read on how to set up permissions and limited permissions just putting in a script Code:
sudo -v |
All times are GMT -5. The time now is 07:50 AM. |