树莓派root账户默认设置是没有密码,且账户是锁定的,开启root账户首先要设置密码。
sudo passwd root
设置密码后要解除root账户锁定状态。
pi@raspberrypi:~ $ sudo passwd --unlock root
passwd: password expiry information changed.
如果上面执行完出现”password expiry information changed.“的提示
是因为新版本ssh默认关闭root登陆,可以修改一下ssh的配置文件
sudo nano /etc/ssh/sshd_config
【Ctrl+W】快捷键,搜索【PermitRootLogin without-password】,修改【PermitRootLogin without-password】为【PermitRootLogin yes】。
# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
PermitRootLogin yes
UsePAM yes
【Ctrl+O】快捷键,保存。
再按一次回车,然后【Ctrl+X】快捷键退出。
至此可以切换到root账户了
su root
可以使用以下命令切回普通用户
su pi