Operating System - Linux
1827849 Members
1949 Online
109969 Solutions
New Discussion

Creating a sudo user in RHAS 2.1

 
SOLVED
Go to solution
Jorge Cocomess
Super Advisor

Creating a sudo user in RHAS 2.1

Greetings,

I would like to know how to setup a user with sudo account. I would like to give this user the option to change the permission on a file from time to time.

I will try to do everything before giving up the root password.

Again, we're currently using RHAS 2.1.

Thank you in advance.

Jorge
25 REPLIES 25
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

install sudo if it is not already installed. then run visudo as root. and add something like this

username ALL = /bin/chmod /path/to/file NOPASSWD: ALL

This will allow the user to run chmod on the file as root. The NOPASSWD will not prompt the user for the users password. If you omit that the user will be prompted for the users password.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Ivan Ferreira
Honored Contributor
Solution

Re: Creating a sudo user in RHAS 2.1

Disagree, if you add that line:

username ALL = /bin/chmod /path/to/file NOPASSWD: ALL

You will be giving the possibility to user "username" to run ALL commands as root. The format of the file is:

USER HOSTS = [(RUN_AS_USER)] [NOPASSWD:] LIST_OF_COMMANDS

For example, using visudo add:

user01 ALL = NOPASSWD: /bin/chmod /path/to/file
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

Ivan,

You are correct. i still get confused with the order in the sudoers file.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

I just need to know where I should add this user-name in the sudo script.

Thank you everyone.

Jorge
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

just add it to the end of the file.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

Okay, I added this line to the end of the sudoers script.
user01 ALL = NOPASSWD: /bin/chmod /path/to/file

Is there anything else I will need to do before I test out by logging as this user??

Thanks so much for your help.

Jorge
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

Hopefully you did not actually add this exact statement.

user01 ALL = NOPASSWD: /bin/chmod /path/to/file

You need to pull the path to a real file.

Ej.

user01 ALL = NOPASSWD: /bin/chmod /data/eng/eng_group_file.out

Otherwise you are good to go.

"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

Hopefully you did not actually add this exact statement.

user01 ALL = NOPASSWD: /bin/chmod /path/to/file

You need to put the path to a real file.

Ej.

user01 ALL = NOPASSWD: /bin/chmod /data/eng/eng_group_file.out

Otherwise you are good to go.

"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

No, that exactly like that. I still have have a permission issue when I tried to do a chmod.

Any ideas?

Jorge
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

What is the issue? can you post the output?
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

I was getting a message stating, "chmod: changing permission of 'test.txt' : operation not permitted"

Jorge
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

as the user did you do the following

# sudo chmod 755 /data/test.txt

the user will need to type the word sudo before the command and arguments.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

Oh no, I did not submit the sudo command before using. let me try it again and let you know.

Thanks so much.

Jorge
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

Is this resolved?
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

Sorry, but I was totally tied up with other operational issues yesterday.

Anyways, this is an error message that I received, "We trust you have received the usual lecture from the local system administrator. It usually boils down to these two things:
1. Respect the privacy of others.
2. Think before you type.

Password:
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

Sorry, but I was totally tied up with other operational issues yesterday.

Anyways, this is an error message that I received, "We trust you have received the usual lecture from the local system administrator. It usually boils down to these two things:
1. Respect the privacy of others.
2. Think before you type.

Password: "


I assume it's asking for the root password.

Please advise.

Jorge
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

seems like something is wrong with the entry in the sudoers file. Can you please post the line that you added.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
skt_skt
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

uid ALL=(root) NOPASSWD: scriptname

try this way.it should work
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

Should I use the actual user_name (test1) or should I be using the UID?? Does the NOPASSWD should be in caps or lowercase characters?

Thanks,
Jorge
Court Campbell
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

Jorge,

I finally tested this on my laptop. Your entry should look like so

user1 ALL = NOPASSWD: /bin/chmod * /tmp/testfile

You need the asterisk as a placeholder for the mode, ie, 0750.
"The difference between me and you? I will read the man page." and "Respect the hat." and "You could just do a search on ITRC, you don't need to start a thread on a topic that's been answered 100 times already." Oh, and "What. no points???"
skt_skt
Honored Contributor

Re: Creating a sudo user in RHAS 2.1

uid ALL=(root) NOPASSWD: scriptname

test1 ALL=(root) NOPASSWD: /xx/yy/zz.ksh
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

I will give that a try and let you all know by tomorrow.

Thank you very much!!

Jorge
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

I guess the easiest thing for me to do was set it this way " User1 ALL = NOPASSWD: ALL "

This will eliminate the password prompt.

Thanks everyone.

Jorge
Jorge Cocomess
Super Advisor

Re: Creating a sudo user in RHAS 2.1

Found what I was looking for.

Thanks,
Jorge