首先通过man 对两条命令查看
man su
SU(1) User Commands SU(1)
用户命令
NAME
su - run a shell with substitute user and group IDs
使用替换用户和组id来运行shell。
Change the effective user id and group id to that of USER.(将有效的用户id和组id更改为USER。)
man sudo
SUDO(8) BSD System Manager’s Manual SUDO(8)
BSD系统管理手册
NAME
sudo, sudoedit - execute a command as another user
sudo,sudoedit—执行作为另一个用户的命令
sudo allows a permitted user to execute a command as the superuser or another user, as specified by the security policy.(sudo允许允许用户按照安全策略指定的超级用户或其他用户执行命令。)
其实两者都可以对当前用户进行切换。
su 需要输入的密码是你将切换后的账户的密码。
su -账户名,可以任意切换到你所需要的账户。不写账户名,默认切换到root。
sudo 需要输入的密码是你当前正在使用的账户的密码。它能暂时获得root用户权限,但有时间限制。所以我们也称sudo 是受限制的su 。