简体   繁体   English

如何使用ruby脚本以ROOT用户身份登录linux终端

[英]How to log in into the linux terminal as ROOT user using ruby script

I want to run a script on remote server using SSH. 我想使用SSH在远程服务器上运行脚本。

I have write all the code which runs properly using system command. 我已经写了所有可以使用系统命令正常运行的代码。

To run my code on remote server I need some packages which I need to install on remote server. 要在远程服务器上运行代码,我需要一些需要在远程服务器上安装的软件包。

To do so I need login into remote terminal as a ROOT user. 为此,我需要以ROOT用户身份登录到远程终端。 When I try to do using Ruby script so I get something like following 当我尝试使用Ruby脚本时,我得到如下所示的信息

[not_root_user@remote_server]$ su
Password: 

I need some command using which I can able to login into the remote server something like following 我需要一些命令,可以使用它登录到远程服务器,如下所示

[not_root_user@remote_server]$ su -p ******
[root@remote_server]# 

Is there any linux command which accepts the password in it? 是否有任何接受密码的linux命令?

So you want your script to act as root? 因此,您想让脚本充当root用户吗?

It's not really recommended, but you can use expect: http://en.wikipedia.org/wiki/Expect 确实不建议这样做,但是您可以使用期望值: http : //en.wikipedia.org/wiki/Expect

The wiki there has a walkthrough for a basic automated telnet session that you could adapt to your needs. 那里的Wiki提供了一个基本的自动telnet会话的演练,您可以适应自己的需求。

However, you're going to have your root password in plain text, which could be a security issue. 但是,您将使用纯文本格式的root密码,这可能是一个安全问题。 If you go that route, I'd definitely obliterate all copies of that script from the universe once this package is installed. 如果走那条路,安装此软件包后,我肯定会从Universe中删除该脚本的所有副本。

But if you're allowing direct root logins, you've already got a bit of a security problem. 但是,如果您允许直接root用户登录,则已经存在一些安全问题。 Sudo works out-of-the-box on every modern linux distro I've used, I'd stick with that, if possible. Sudo可以在我使用的每个现代linux发行版中直接使用,如果可能的话,我会坚持使用。

Another option which is equally tasteless would be to set up root-to-root login without a password via ssh. 同样无味的另一种选择是通过ssh设置没有密码的root-to-root登录。

Sudo would be my first option to getting around this. Sudo将是我解决此问题的首选。 Although not the best option. 虽然不是最佳选择。

You can also use Key authentication with SSH, and if password authentication is turned off there is no need to enter a password. 您还可以将密钥身份验证与SSH一起使用,如果密码身份验证已关闭,则无需输入密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM