Commands.page Logo

Can I Alias Commands in the Sudoers File in Ubuntu?

This guide answers whether you can create command aliases within the Ubuntu sudoers file. It outlines the specific function of sudoers configurations, clarifies the difference between permission grouping and shell shortcuts, and directs you to the correct configuration files for creating usable command aliases in your terminal.

The short answer is no. You cannot create functional command aliases in the sudoers file that simplify how you type commands in your terminal. While the sudoers file does support a directive called Cmd_Alias, it serves a different purpose than standard shell aliases.

In the sudoers file, Cmd_Alias is used strictly for grouping commands to manage permissions. For example, you can group /bin/ls and /bin/cp under a name like FILE_CMDS to easily grant a user sudo access to both. However, you cannot type sudo FILE_CMDS to execute them. You must still type the full command, such as sudo ls. The alias exists only within the logic of the sudo security policy, not as a shortcut for the user.

If your goal is to create shortcuts for commands you type regularly, you should define shell aliases instead. These belong in your shell configuration file, such as ~/.bashrc for Bash or ~/.zshrc for Zsh. To create an alias, open your configuration file and add a line like alias ll='ls -l'. After saving the file, run source ~/.bashrc to apply the changes immediately.

For sudo-specific shortcuts, you can alias the sudo command itself within your shell configuration. For instance, adding alias sd='sudo' to your .bashrc allows you to type sd ls instead of sudo ls. Keep the sudoers file reserved for security policies and privilege management to maintain system stability and security.