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

相关推荐
瀚高PG实验室9 分钟前
如何将HGDB安全版(RPM包形式)安装在非root用户下
服务器·网络·安全·瀚高数据库
python百炼成钢16 分钟前
50.linux_USB驱动
linux·运维·服务器·驱动开发
路由侠内网穿透.18 分钟前
本地部署问答社区 Apache Anwser 并实现外部访问
服务器·windows·网络协议·apache·远程工作
jay35 分钟前
ens2f0 IP 远程连线,balance-alb 模式配置双网卡(ens2f0 + ens6f0)Bond,避免断网
linux·运维·服务器·网络·tcp/ip
Evan芙1 小时前
用Shell脚本破解经典鸡兔同笼问题
linux·运维·网络
悟能不能悟1 小时前
登录jenkins默认用户密码
运维·jenkins
大大大水蜜桃1 小时前
Nginx HTTPS服务搭建实验
运维·nginx·https
BugShare2 小时前
粗心大意必酿大祸,记录nginx配置文件的一次闹剧
运维·nginx
꧁坚持很酷꧂2 小时前
Ubuntu系统下Qt程序连接串口设备没有问题,但运行时出现Permission denied的解决方法
linux·qt·ubuntu
jerryinwuhan2 小时前
机器人控制程序
linux·运维·网络