How to restrict rm -rf * to users other than root?


 
Thread Tools Search this Thread
Operating Systems Solaris How to restrict rm -rf * to users other than root?
# 1  
Old 08-02-2012
Java How to restrict rm -rf * to users other than root?

I'm using Solaris 10. I want to restrict users from executing this dangerous command.

Code:
rm -rf *

But they should be able to perform the below actions:

Code:
rm -rf *.*
rm -rf filename
rm -rf directory

Is it possible? If yes then pls let me know how to do it?
# 2  
Old 08-02-2012
Yes, everyone's nightmare.

Have you seen this before?

Safe-rm

I also remember sometime ago being told about sysadmins creating a file with some escape characters in the name at root (/) which caused rm -r to fall over when executed at that level in the filesystem. Unfortunately, I can't remember how it was done. However, some of the coding/scripting experts on this forum might have something to say about that.

Last edited by hicksd8; 08-02-2012 at 10:13 AM..
# 3  
Old 08-02-2012
Why would *.* be much safer? That could potentially match . or .. on some systems. Besides, you can't really disable some globbing but not others.

What I usually see done to "safe" rm for root is putting alias rm="rm -i" in root's profile, so rm prompts for every single file removal.
# 4  
Old 08-02-2012
Corona688: If the alias is added then all rm command would prompt the user input, this will affect any scripts that is used to clean the logs/files.
# 5  
Old 08-02-2012
No, they don't, actually. Aliases apply to interactive logins, only interactive logins, and nothing but interactive logins.

If you type 'rm' directly into a root terminal where rm is aliased to rm -i, it will run 'rm -i'.

It does that absolutely nowhere else. Not inside scripts or utilities, even if you run them from that same terminal.

Which is a pretty good reason to use an alias for this, actually, and why you actually see that sort of thing done a lot.

Last edited by Corona688; 08-02-2012 at 12:24 PM..
This User Gave Thanks to Corona688 For This Post:
# 6  
Old 08-02-2012
This might help. It's a bit long-winded, but could accomplish what you want by adding a test in the alias command:

Code:
alias rm="[ $(id | cut -d'=' -f2 | cut -d'(' -f1) -ne 0 ] && rm -i"

So if the uid equals 0 (or substitute whichever uid you want to omit from being prompted), then skip prompting, while other users will be prompted.

Hope this helps.
This User Gave Thanks to in2nix4life For This Post:
# 7  
Old 08-02-2012
id -u (if available on your machine) might save you all the cutting...

Last edited by RudiC; 08-02-2012 at 12:57 PM.. Reason: needs to be the -u option , not g nor G
This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Procedure to restrict direct access as root

Hello, I would like to confirm whether the below procedure is correct. disabled direct super user access on AIX server using below procedure. Please let me know if there is any additional step. 1) confirm the access to HMC, console to reach the LPARs 2) chuser rlogin=false root ... (3 Replies)
Discussion started by: dio34
3 Replies

2. Shell Programming and Scripting

How to restrict root user from running some commands

is it possible that we can restrict the root user if he runs some commands?? e.g i want if root runs command 'rm etc/passwd', he shoudn't be able to run command and throws error :confused: (3 Replies)
Discussion started by: sheelsadan
3 Replies

3. Solaris

To restrict the users not to change the passwords for NIS users

Hi All, How to restrict the NIS users not to change their passwords in for NIS users?? and my NIS user is unable to login to at client location what could be the problem for this ? Any body can help me. Thanks in advance. (1 Reply)
Discussion started by: Sharath Kumar
1 Replies

4. Linux

Restrict NFS access to root

Hi Everybody, If there is a general NFS share in the LAN and for example this share has three files - a, b, c is there any way to restrict file access to the root user of one particular host(falcon) in the same LAN environment while the normal users from the same host(falcon) should be able... (4 Replies)
Discussion started by: sudhirav
4 Replies

5. Red Hat

Restrict local users to access ftp

Hi, I had installed vsftp in rhel5 and i want to restrict all the local users from accessing the ftp. i want to allow specific users to access the ftp server. Request you to please help. Thanks & regards Arun (1 Reply)
Discussion started by: Arun.Kakarla
1 Replies

6. UNIX for Advanced & Expert Users

Restrict access to specific users.

Hi All! I would like to know if there is any specific way by which I can restrict access to apecific users (ip addresses). OS : Red hat linux Thanks! nua7 (6 Replies)
Discussion started by: nua7
6 Replies

7. Shell Programming and Scripting

how to restrict FTP users not to delete their files

Hello all, We have an FTP Server setup with VSFTPd and its working fine without anonymous login (we must maintain this standard) The requirement is to restrict users not to overwrite (and delete) their files. In other words, once their files are uploaded to FTP Server, they should not be... (1 Reply)
Discussion started by: prvnrk
1 Replies

8. Solaris

how to restrict the perticular commands to users

Hi all, How to restrict the perticular commands to users(or perticular users) in solaris10? Could you please assist me the precedure for above issue. Thanks & Regards krishna (0 Replies)
Discussion started by: krishna176
0 Replies

9. UNIX for Dummies Questions & Answers

Restrict users to certain functions

Hi Gurus, Tried searching for something similiar in this forum but not really what i want. This is my case: I have about 20 users running on sun workstation. We have done a upgrade recently and right now it seems that the users can access to terminal and console which they are not suppose... (12 Replies)
Discussion started by: lweegp
12 Replies

10. UNIX for Dummies Questions & Answers

Restrict users to ther home directory

Hello! I want users in a certain group to be restricted to their home directory. So that they have full access to all files and folders in their home directory but the cant go to any directory above. Does anyone know how to do this? Anders (1 Reply)
Discussion started by: alfabetman
1 Replies
Login or Register to Ask a Question