新安装的Debian 12系统开启root用户和ssh登录权限

安装好系统之后,在终端中进入root账户报错,ssh也无法连接

一、配置IP地址

先使用普通用户登录,设置IP地址和DNS(需要连接外网更新软件源)

二、开启root账户

重启系统,键盘不停敲击e键进入编辑模式,找到 linux 开头的行(需要按↓键),移动光标到这一行的最后,添加:init=/bin/bash

按 Ctrl + X 启动

系统会直接进入一个 root shell 终端,不需要密码

挂载根分区为可读写模式

mount -o remount,rw /

设置新的 root 密码:

passwd root

重启系统

exec /sbin/init

三、更新镜像源

终端登录root用户

su - root

修改源文件,移除 cdrom 源

nano /etc/apt/sources.list

注释掉(前面加个 #)deb cdrom://Debian GNU/Linux 12.13.0 _Bookworm_ ... bookworm main

添加清华源

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware

Ctrl+O保存,Enter, Ctrl+X退出 nano。

四、安装ssh服务

更新源并安装 SSH

apt update

apt install -y openssh-server

确认 SSH 服务状态

systemctl status ssh

看到 active (running) 就说明服务正常了

启动并设置开机自启

systemctl enable --now ssh

五、允许 SSH 直接登录 root

不开通,会被拒绝登录。

编辑 SSH 配置文件

nano /etc/ssh/sshd_config

#PermitRootLogin prohibit-password

改为

PermitRootLogin yes

PasswordAuthentication yes

Ctrl+O保存,Enter, Ctrl+X退出 nano。

然后重启 SSH 服务

systemctl restart ssh

相关推荐
布鲁飞丝5 小时前
vivo Pulsar 万亿级消息处理实践()-Ansible运维部署
运维·ansible
XR1234567885 小时前
企业全光网络架构选型技术白皮书:从物理层到运维层的全链路分析
运维·网络·架构
HiDev_6 小时前
【非标自动化】2、认识元器件(直线模组)
运维·自动化
龙仔7257 小时前
人大金仓 KingbaseES V8 只读账号创建完整运维笔记
运维·笔记·sql·人大金仓
我不管我就要叫小猪7 小时前
嵌入式Linux----网络通信
linux·运维·服务器
江湖有缘7 小时前
Docker实战 :使用Docker部署OneTerm堡垒机
运维·docker·容器
姜太小白8 小时前
【Linux】df -h 卡住问题的通用排查与解决方案总结
linux·运维·php
fengyehongWorld8 小时前
Linux 终端快捷键
linux·运维
看昭奚恤哭9 小时前
平滑加权轮询负载均衡的底层逻辑
运维·负载均衡
hyf3266339 小时前
泛程序:从零开始搭建稳定程序项目框架
运维·服务器·爬虫·百度·seo