ubuntu 配置root远程登录shell脚本

以下是一键配置脚本,直接新建rootlogin.sh脚本文件,打开后把以下命令粘贴进去然后,运行脚本文件即可。

shell 复制代码
#!/bin/bash

 #set root password
sudo passwd root
 
#notes Document content
sudo sed -i "s/.*root quiet_success$/#&/" /etc/pam.d/gdm-autologin
sudo sed -i "s/.*root quiet_success$/#&/" /etc/pam.d/gdm-password
 
#modify profile
sudo sed -i 's/^mesg.*/tty -s \&\& mesg n \|\| true/' /root/.profile
 
#install openssh
sudo apt install openssh-server
 
#delay
sleep 1
 
#modify conf
sudo sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
 
#restart server
sudo systemctl restart ssh

运行脚本:

shell 复制代码
sh rootlogin.sh

参考资料:ubuntu22.04桌面版开启root用户登陆并开启root用户远程ssh连接

相关推荐
想你依然心痛44 分钟前
嵌入式Linux安全加固:SELinux、Capabilities与Seccomp——强制访问控制与沙箱
linux·运维·安全
AAA@峥2 小时前
容器数据不丢失:Docker 分层存储 + Volume 共享、备份迁移完整指南
运维·docker·容器
MDM.Plus2 小时前
苹果MDM技术演进:从远程控制到设备信任体系的构建
运维·服务器·安全·ios·mdm·手机店
REDcker2 小时前
macOS 挂载 Linux 远程目录详解
linux·运维·macos
2601_961593422 小时前
Mac 上搭建Linux环境吗?VMware + CentOS Stream 9 镜像快速部署
linux·运维·ide·macos·centos
写代码的学渣3 小时前
Linux systemd 开机启动日志逐行详细解析报告
linux·运维·服务器
田里的水稻3 小时前
EP_XML\JSON配置文件和YAML
xml·运维·人工智能·机器人·自动驾驶·json
阿成学长_Cain3 小时前
Linux telinit 命令详解:运行级别切换|关机重启|系统维护一站式掌握
linux·运维·前端·网络
QXWZ_IA4 小时前
油气储罐沉降监测用什么技术方案最好?千寻自动化监测+次声波泄漏方案
运维·科技·自动化·能源
NiceCloud喜云4 小时前
Anthropic 一周三连发:Cowork 多端、Fable 5 按需付费、J-space 论文的技术解读
java·服务器·网络·人工智能·ai