How to fix the problem that Raspberry Pi cannot use the root user for SSH login All In One
1.How to fix the bug that there is no signal when the Raspberry Pi is connected to a monitor with an HDMI cable All In One2.Raspberry Pi command line tools vcgencmd All In One3.Python rpi_ws281x library All In One4.Adafruit CircuitPython NeoPixel All In One
5.How to fix the problem that Raspberry Pi cannot use the root user for SSH login All In One
6.How to modify the hostname and username and password of Raspberry Pi All In One7.树莓派 4B 核心电子元器件图解 All In One8.Linux install vim errors All In One9.How to boot the Raspberry Pi system from a USB Mass Storage Device All In One10.How to Control an External USB Web Camera Using a Raspberry Pi All In One11.ARM Cortex-A72 CPU All In One12.Linux shutdown & reboot & poweroff All In One13.软路由 & 旁路由 All In One14.How to change the default Python2 to Python3 on Linux All In One15.Raspberry Pi 4 Model B Product Information Portal All In One16.use SSH to connect to Raspberry Pi methods All In One17.国产单片机开发板 All In One18.How to use Raspberry Pi scan bluetooth devices All In One19.How to use the Raspberry Pi and Python to control a DHT11 wet and temperate module All In One20.How to use the Raspberry Pi and Python to control a buzzer All In One21.gpiozero API All In One22.RPi.GPIO API All In One23.Node.js & Raspberry Pi & WS2812B RGB LEDs strip All In One24.Raspberry Pi 3 Model B and Raspberry Pi 3 Model B+ and and Raspberry Pi 4 Model B All In One25.How to use Linux command or Python code get Raspberry PI's Temperature All In One26.How to connect to multiple SSD1306 OLED Displays using Raspberry Pi GPIO I2C PIN All In One27.Raspberry Pi & 0.96 inch SSD1306 OLED display All In One28.WS2812B RGB LED 灯带外接电源所需要的电压计算公式 All In One29.Raspberry Pi GPIO pins All In One30.如何使用蓝牙控制树莓派 All In One31. Raspberry Pi & Experience AI All In One32.如何修复树莓派在更换了一个 SD 系统卡后,无法使用 SSH 登录问题 All In One33.How to use the Raspberry Pi to study the Linux kernel source code All In One34.Raspberry Pi 设置开机登录后自启动脚本 All In One35.How to use SSH to access the Raspberry Pi without know the Wi-Fi IP address All In One36.Raspberry Pi Code Editor All In One37.Linux copy from pipe command All In One38.how to use crontab to send an email on Linux All In One39.macOS Terminal & Raspberry Pi client_loop: send disconnect: Broken pipe All In One40.Raspberry Pi crontab not work bug All In One41.Raspberry Pi GPIO 针脚图解教程 All In One42.how to get Raspberry Pi System Information All In One43.2023 最新的如何树莓派上安装中文输入法和设置中文语言环境教程 All In One44.Linux change archive mirror All In One45.How to publish a Linux package to mirror All In One46.Raspberry Pi 3B won't turn on after being powered on All In One47.Raspberry Pi Debug Probe All In One48.How to find the "usbmodem" of Raspberry Pi Pico on macOS All In One49.How to check the USB devices connected to Linux by using Terminal All In One50.Raspberry Pi Imager All In One51.use macOS terminal can not install MicroPython on Raspberry Pi Pico bug All In One52.Raspberry Pi Pico All In One53.macOS 如何通过 SSH 访问树莓派 All In One54.面包板使用教程 All In One55.Raspberry Pi Pico & MicroPython All In One56.Raspberry Pi & Python & GPIO All In One57.Raspberry Pi Remote Access All In One58.Raspberry Pi 4 B 8G All In One59.How to use macOS to connect to Raspberry Pi without the monitor All In One60.Linux 关机命令 All In One61.Raspberry Pi 5 All In One62.TensorFlow Lite & Raspberry Pi All In One63.how to install GitLab on Raspberry Pi OS 64.Raspberry Pi & GPIO All In One65.Raspberry Pi 电路图模拟器 All In One66.树莓派 4B 入门教程 All In One67.如何在树莓派上搭建 gitlab 服务 All In One68.Raspberry Pi & Node.js & WebSockets & IM69.Raspberry Pi & Raspberry Pi 4 All In One70.IoT & Raspberry Pi71.NMAP 使用教程 All In One72.如何使用 config.txt 配置 Raspberry Pi 3 的各种信息!73.如何在没有显示器的情况下查看 Raspberry Pi 3 的 IP 地址信息 All In One74.How To Install Linux & Nginx & MySQL & PHP (LEMP) stack on Raspberry Pi 3 All In One75.如何启用树莓派的硬件看门狗功能,让它在系统宕机时可以自动重新开机 All In One76.如何在 Raspberry Pi 树莓派上安装浏览器的详细教程 All In One77.树莓派(raspberry pi 3) 中文界面支持的设置,安装中文环境,中文输入法 All In One78.2016 最新的树莓派3 上手评测图解教程新手必看 All In OneHow to fix the problem that Raspberry Pi cannot use the root user for SSH login All In One
如何修复树莓派无法使用 root 用户进行 SSH 登录的问题
应用场景
修改树莓派默认的 pi
用户名和密码后,需要使用 root
用户进行 SSH
登录;
- 对
pi/home
文件夹进行备份
,复制到新用户下xgqfrms/home
- 备份后,要
删除
pi 用户, 必须切换到其他用户,毕竟 pi 用户不能自己删除自己呀!⚠️
# 添加新用户 xgqfrms, 并且把该用户添加到 sudo 组下
$ sudo useradd -m xgqfrms -G sudo
# 设置新用户的密码
$ sudo passwd xgqfrms
# 备份整个 home 目录
# $ cp /home/pi /home/xgqfrms
# 仅备份开机后登录自启动配置文件
$ cp /home/pi/.profile /home/xgqfrms/.profile
# 仅备份 home 目录下的 Desktop 目录
$ cp -r /home/pi/Desktop /home/xgqfrms/Desktop
# 仅删除用户 pi,保留 pi 的家目录 /pi/home/ (可以复用)
$ sudo deluser pi
# 永久的删除用户 pi 的家目录
$ sudo deluser -remove-home pi
给 root 设置密码后,直接修改并复用
/pi/home/
的文件夹 ???
# 待验证 ❓
$ man usermod
# rename, home directory
$ usermod -l xgqfrms pi
# reflect
$ usermod -m -d /home/xgqfrms xgqfrms
# test
$ sudo apt-get update
# disable the root account by locking the password
$ sudo passwd -l root
errors ❌
# pi 用户切换到 root 用户
$ sudo su
# 设置 root 用户的密码
root@raspberrypi:/home/pi# passwd
新的 密码:
重新输入新的 密码:
passwd:已成功更新密码
# 退回到 pi 用户
root@raspberrypi:/home/pi# exit
exit
# pi 用户退出 SSH 登录
$ logout
# pi 用户 SSH 登录正常 ✅
$ ssh pi@raspberrypi.local
# 密码没有错误,但是 root 用户一直无法 SSH 登录 ❌
$ ssh root@raspberrypi.local
root@raspberrypi.local's password:
Permission denied, please try again.
root@raspberrypi.local's password:
Permission denied, please try again.
root@raspberrypi.local's password:
root@raspberrypi.local: Permission denied (publickey,password).
solution ✅
-
要给 root 设置登录密码,默认 root 没有密码
-
要开启 root 的 SSH 登录权限,默认是不允许 root 进行 SSH 访问的
/etc/ssh/sshd_config
# 修改
$ sudo vim /etc/ssh/sshd_config
systemctl
# 重启 sshd 服务
$ systemctl restart sshd
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
重新启动“ssh.service”需要认证。
Authenticating as: ,,, (pi)
Password:
==== AUTHENTICATION COMPLETE ===
prohibit-password
=>yes
# Authentication:
# 临时打开 ⚠️
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
# Authentication:
+ # 临时打开 ⚠️
+ LoginGraceTime 2m
+ PermitRootLogin yes
+ StrictModes yes
- # LoginGraceTime 2m
- # PermitRootLogin prohibit-password
- # StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
demos
SSH &
/etc/ssh/sshd_config
$ cat /etc/ssh/sshd_config
$ cat /etc/ssh/sshd_config
# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented. Uncommented options override the
# default value.
Include /etc/ssh/sshd_config.d/*.conf
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
# 临时打开 ⚠️
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2
#AuthorizedPrincipalsFile none
#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody
# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no
# 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'.
UsePAM yes
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem sftp /usr/lib/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
passwd
& useradd
$ man passwd
$ man passwd > passwd.md
$ cat ./passwd.md
$ man useradd
$ man useradd > useradd.md
$ cat ./useradd.md
passwd generator
# 密码生成器
$ openssl passwd -6
Password:
Verifying - Password:
$6$lamhqyRZlhl38Rzw$G2bIMwmYKnonpg1bLXFiZR233zjkXKzPb12mHD0dsRuWJvTl.be6uJmBl8pcWx2k6n2EeoORnjZawJDfcCATT/
/boot/userconf.txt
$ cat /boot/userconf.txt
pi:/4g6TptuTP5B6
https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-a-user
refs
https://www.cnblogs.com/xgqfrms/p/17446689.html#5181665
©xgqfrms 2012-2025
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17447592.html
未经授权禁止转载,违者必究!
合集:
Raspberry Pi
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
2022-05-31 Apple iPhone 12 Pro 扬声器水流声 bug All In One
2022-05-31 Media Source Extensions All In One
2021-05-31 ES6 destructuring assignment & default value & rename All In One
2021-05-31 default-passive-events All In One
2021-05-31 nrm & cnpm All In One
2020-05-31 Wi-Fi 6
2020-05-31 bind & this & new & arrow function