简体   繁体   中英

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.

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. When I try to do using Ruby script so I get something like following

[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?

So you want your script to act as root?

It's not really recommended, but you can use 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.

However, you're going to have your root password in plain text, which could be a security issue. If you go that route, I'd definitely obliterate all copies of that script from the universe once this package is installed.

But if you're allowing direct root logins, you've already got a bit of a security problem. Sudo works out-of-the-box on every modern linux distro I've used, I'd stick with that, if possible.

Another option which is equally tasteless would be to set up root-to-root login without a password via ssh.

Sudo would be my first option to getting around this. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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