用于 SSH 的库
建议图书馆使用 SSH。主要要求是使用 sudo 实用程序正常操作。 我已经尝试过了,我正在遭受什么:
- paramiko - 根本无法 sudo,在调用 STDIN 密码后尝试,但 sudo 写道,然后输入:“No ttys present”
- pxssh - mmmmmm,非常慢,非常非常慢,尴尬的
- 结构 - sudo 只能在理想的世界中使用,因为需要与不同的用户合作以及我需要发送密码的地方?
是否有可以与 sudo 一起使用的普通库?
counsel to the library to work with SSH. The main requirement is normal operation with the utility sudo.
I have already tried and what I am suffering:
- paramiko - can not sudo at all, trying after a call to serve in STDIN password, but sudo wrote that then type: "No ttys present"
- pxssh - mmmmmm, very slow, very very slow, awkward
- fabric - can sudo only in what is an ideal world, as there is to work with different users and where i need send password ?
Have normal libraries that work with sudo, or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
与其强制 sudo 在没有 tty 的情况下工作,为什么不让 Paramiko 为您分配一个 TTY?
Paramiko 和 Pseudo-tty 分配
Rather than force
sudo
to work without a tty, why not get Paramiko to allocate you a TTY?Paramiko and Pseudo-tty Allocation
我认为您正在寻找fabric。
I think you are looking for fabric.
您可以使用“requiretty”设置将 sudo 配置为在没有真实终端的情况下工作。来自 sudoers 手册:
这对我来说对 paramiko 有用。根据您在做什么,您还可以查看类似 pexpect 的内容。
You can configure sudo to work without a real terminal with 'requiretty' setting. From sudoers manual:
This works for me with paramiko. Depending o what are you doing, you can also look at something like pexpect.
我一开始在使用 pxssh 时遇到了同样的问题:速度非常慢!
这是我发现的一种让它运行得更快的方法:
关键部分是
s.login() 中的
。s.PROMPT = "#"
和auto_prompt_reset=False
此方法要求您知道提示的模式(在我的例子中是“#”,我认为 PROMPT 属性可以设置为正则表达式)。
I had the same problem with pxssh at first: it was extremely slow!
Here is a way I found to make it run quicker:
The key part is
s.PROMPT = "#"
andauto_prompt_reset=False
ins.login()
.This method requires that you know the pattern for the prompt (in my case it is "#", I think the PROMPT attribute can be set to a regular expression).
我在 pxssh 上的登录速度也遇到了一些问题。我尝试使用上面引用的代码,但仍然需要 10 多秒才能登录。使用original_prompt参数为我解决了这个问题。您需要确保将 Original_prompt 设置为首次 ssh 进入计算机时看到的内容,在我的例子中以“>”结尾。
I also had some problems with login speed on pxssh. I tried using the code referenced above, but still was seeing 10+ seconds just to login. Using the original_prompt argument fixed the issue for me. You need to make sure to set the original_prompt to what you see when you first ssh into the machine, which in my case ended in '>'.