Linux服务器中的自动根login

我试图在不同的Linux服务器发行版(Fedora,Ubuntu,Centos等)中执行testing。

我知道有一个init系统可以允许程序在启动后执行(不需要login)。 问题是,我不想为发行版之间的每个不同的初始系统有一个特殊的情况。 开机后有没有办法让root自动login?

通过这样做,我可以有任何发行版相同的shell脚本。 还是有办法解决这个问题?

我知道有一个init系统可以在启动后允许程序执行(不需要login)。

不幸的是,这些日子里没有一个 init系统有6个stream行的init系统。 例如sysv init,systemd,暴发户等

无论如何,如果你真的想要一个系统为你提供一个具有root权限的控制台,你可能会想要更新你的init系统。

我这样做是为了在我的几个系统上的串行端口。 我有两个非常不同的configuration,我只用了两个不同版本的Debian。 我无法想象,你将能够提出一个适用于所有发行版的方法。 如何开始就没有一致性。 Systemd应该在发行版中非常相似,但还没有被广泛接受。

Debian与sysv初始化(wheezy)在串行端口下降到根

# /etc/inittab ... # serial port getty spawns sulogin, which drops to a root shell # on debian if root has a disabled password T0:23:respawn:/sbin/getty -n -l /sbin/sulogin -L ttyS0 57600 vt102 ... 

系统(jessie)的Debian放在串口上

 #/etc/systemd/system/getty.target.wants/[email protected] # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. [Unit] Description=Serial Getty on %I Documentation=man:agetty(8) man:systemd-getty-generator(8) Documentation=http://0pointer.de/blog/projects/serial-console.html BindsTo=dev-%i.device After=dev-%i.device systemd-user-sessions.service plymouth-quit-wait.service After=rc-local.service # If additional gettys are spawned during boot then we should make # sure that this is synchronized before getty.target, even though # getty.target didn't actually pull it in. Before=getty.target IgnoreOnIsolate=yes [Service] ExecStart=-/sbin/agetty -n -l /sbin/sulogin --keep-baud 115200,38400,9600 %I $TERM Type=idle Restart=always UtmpIdentifier=%I TTYPath=/dev/%I TTYReset=yes TTYVHangup=yes KillMode=process IgnoreSIGPIPE=no SendSIGHUP=yes [Install] WantedBy=getty.target 

你最好的办法就是放弃以root身份login的想法,改为使用像puppet这样的configurationpipe理工具,或者可以为你抽象出一些不同的发行版本差异。 让这个工具触发你的testing运行。

您添加了一条评论:“我有一个程序需要在不同的Linux发行版上进行物理testing,以报告性能”

在这种情况下,你可能要考虑使用docker ,这样你并不需要一个完整的操作系统或任何东西…但是如果你的程序出于某种原因需要在一个物理实例上运行,你可能需要检查一些作业执行环境像jenkins

如果是命令行编程,更好的方法是通过SSH执行。 此外,您可以使用SSH密钥login而无需密码。

我很困惑你想要什么,但是如果你想在Linux上启动后以root身份运行某些东西,请将它放在大多数发行版的这里:

 /etc/rc.local 

或者有时候

 /etc/rc.d/rc.local