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连接

相关推荐
sunz_dragon6 分钟前
Claude Code / Codex Git 版本管理完整使用指南
服务器·人工智能
领尚7 分钟前
openclaw 极简安装(Ubuntu 24.04 server)
linux·运维·ubuntu
Gofarlic_OMS22 分钟前
Windchill的license合规使用报告自动化生成与审计追踪系统
大数据·运维·人工智能·云原生·自动化·云计算
SPC的存折29 分钟前
3、主从复制实现同步数据过滤
linux·运维·服务器
SPC的存折31 分钟前
openEuler 24.03 MariaDB Galera 集群部署指南(cz)
linux·运维·服务器·数据库·mysql
xcbrand33 分钟前
文旅行业品牌策划公司找哪家
大数据·运维·人工智能·python
SPC的存折1 小时前
MySQL 8.0 分库分表
linux·运维·服务器·数据库·mysql
风吹迎面入袖凉1 小时前
【Redis】Redisson分布式锁原理
java·服务器·开发语言
cyber_两只龙宝1 小时前
【Oracle】Oracle之DQL中WHERE限制条件查询
linux·运维·数据库·云原生·oracle
斌味代码1 小时前
Shell 性能监控:指标采集、告警规则与可视化大盘设计
运维