简体   繁体   English

一对一登录到多个UNIX服务器,然后使用perl执行命令

[英]Login to the multiple UNIX servers one by one and then execute the command using perl

I am trying to login to the multiple UNIX servers using SSH one by one and then need to be executed the commands without prompt the username and password. 我试图使用SSH一次登录到多个UNIX服务器,然后需要执行命令而不提示用户名和密码。

Is there any chance to do this from Perl ? Perl有机会这样做吗?

Yes, this can be done, and if you do, it's best to use a module for it, eg Net::OpenSSH . 是的,可以这样做,如果这样做,最好使用一个模块,例如Net :: OpenSSH

But this is probably a bad idea. 但这可能是一个坏主意。 You will need to specify the username and password in plaintext in a place where your Perl script can read them (eg in its source code). 您需要在Perl脚本可以读取它们的位置(例如,在其源代码中)以纯文本形式指定用户名和密码。 Anyone who can read your script can also read the username and password, and execute any remote command that using them permits. 可以读取您的脚本的任何人都可以读取用户名和密码,并执行使用它们允许的任何远程命令。

So you might as well create a different piece of information that can be read by anyone who can read the Perl script, and use that to authenticate: a passwordless SSH key. 因此,您最好创建一条不同的信息,任何可以阅读Perl脚本的人都可以阅读,并使用该信息进行身份验证:无密码的SSH密钥。

Create one and add its public key to the authorized keys on the host(s) you want to execute your remote command on. 创建一个并将其公共密钥添加到要在其上执行远程命令的主机上的授权密钥。 Use that key to execute the remote command. 使用该键执行远程命令。 This is as least as safe as hardcoding the username and password in a place where the Perl script can read them. 这至少与在Perl脚本可以读取用户名和密码的地方对它们进行硬编码一样安全。

In fact, it is safer: you can restrict the use of that key to the command you want to execute . 实际上,这是更安全的:您可以将该键的使用限制为要执行的命令

And you won't need a Perl script to execute the remote command. 而且您将不需要Perl脚本来执行远程命令。

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

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