Disable a command

I need to disable a command. For example - disabling "ls" means that when someone type "ls" - nothing happens .

Somebody help ???? :confused::confused::confused:

For which all users do you need to disable it? For all the users or just some specific user?

If it is for all the users you can always move the executable to some other place or just rename it.

I need to do it for all users. Can you show me more detail, i'm just a newbie :(:(:frowning:

Lets say you want to disable ls . First find where the executable is:

which ls
/usr/bin/ls

This will give you the actual file name. Now rename it:

mv /usr/bin/ls /usr/bin/ls_disabled

And if in some point of time you need to enable the command, then rename it to its original name.

1 Like

Why in the world would you think you "need" to disable ls ?

Disabling or removing any system supplied utility may turn your system into an expensive doorstop. This is a VERY bad idea. Your boot scripts may stop working, your system administration scripts may stop working, and your user's scripts will stop working.

1 Like

WOW it works. Thank chacko193 (^__^)

---------- Post updated at 01:48 AM ---------- Previous update was at 01:46 AM ----------

Just an example. I need to disable some commands for security reason.

By all means, why is ls a security issue?
I'd rather deny access to folders conent (by user/group permissions), rather than disable ls alltogether...

See: chmod / chown / usermod
And depending on your OS, maybe (pam-)selinux

Hope this helps

1 Like

I do agree with Don, this might help you

  1. change directory permission first, so that only the user can edit contents of home directory
chmod 755 /home/user
  1. Disable loading of .bashrc file, will move to some safe place...
mv /home/user/.bashrc /root/some_safe_place/backup/
  1. Create a .bash_profile file and add all alias
touch /home/user/.bash_profile

Some_restricted functions file look like this

$ cat somefile

# some disabled aliases
alias ls="echo ls "  
alias rm="echo rm" 

# Some allowed aliases
alias f='ferret -nojnl'
alias cls='clear'
alias cp='/bin/cp -i'
alias mv='/bin/mv -i'
alias md='mkdir'
alias m='/usr/local/Software/Matlab_09/bin/./matlab'
alias ncml='/usr/local/www/html/TOMCAT_DEMO/tomcat/JAVA/jre1.7.0_45_64/bin/java -jar /home/akshay/Documents/toolsUI-4.2.jar &'

.bash_profile will be something like this


# Get the aliases and functions
if [ -f ~/.somefile ]; then
	. ~/.somefile
fi

# Some User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
  1. Change the ownership of the user's .bash_profile to root
chown root:root /home/user/.bash_profile
  1. Disable write permission
chmod 755 /home/user/.bash_profile
1 Like

Or just remove the (execute) rights for the group "other",
which means that only the owner (in most cases "bin") or "root" will be able to execute this command.

example:
chmod 550 /usr/bin/<your_secure_command>

verify:

ls -la /usr/bin/<your_secure_command>
-r-xr-x--- 1 bin bin 26990 Sep 05 2012 /usr/bin/<your_secure_command>

Regards