To restrict certain commands in Zsh for security purposes, you can use the ‘disable’ built-in command. This command disables a shell builtin, which means it cannot be executed and no error message is printed if these are called. For instance, to disable the ‘rm’ command, you would type ‘disable rm’.
Another method involves using aliasing to override dangerous commands. By creating an alias that points to a safer version of the command or simply echoes a warning message instead of executing the command, you can prevent accidental misuse. For example, ‘alias rm=’echo “This command is disabled”‘.
Lastly, consider setting up restricted mode (rsh) or rbash. In this mode, users can’t change directories, specify paths for command execution, or execute scripts calling /bin/zsh or /usr/bin/zsh, enhancing security.