The sudo and su commands belong to the group of commands every Linux user comes across. Because they are similar in syntax and have overlapping functions, many new users are unsure when to use one over the other. Both su and sudo elevate privileges assigned to the current user, but not in the same way.
The main difference between the two is that su requires the password of the target account, while sudo requires the password of the current user. It is generally much safer to use sudo since it doesn’t include exchanging sensitive information or settings.
Additionally, it is advisable to stick to sudo when performing tasks that require root privileges.
By doing so, the current user is only granted privileged for the specified command.
On the other hand, su switches to the root user completely, exposing the entire system to potential accidental modification.
Therefore you need to seriously consider which you need to use for what.