This article introduces how to check if a user has sudo privileges in Linux/Ubuntu.
Use sudo -v.
# If you have privileges, nothing is output
$ sudo su -
root@mypc:~# sudo -v
root@mypc:~# logout
yuis@mypc:/mnt/c/pg/gits/obfuscatify.sh$ sudo -v
yuis@mypc:/mnt/c/pg/gits/obfuscatify.sh$
# If you don't have privileges, a warning appears
[yuis@sv2031 home]$ sudo -v
User yuis is not allowed to execute sudo on sv2031. Sorry.
This method not only checks if you have sudo privileges, but also allows you to update the sudo expiration time by entering the sudo password.
By checking sudo privileges, you can confirm whether you need to enter the sudo password before executing commands that require sudo privileges.