jeffreywildman / homebrew-virt-manager

A set of homebrew formulae to install virt-manager and virt-viewer on MAC OSX
1k stars 266 forks source link

Automatic frequent password entry#自动频繁的输入密码 #190

Open JunBys opened 2 years ago

JunBys commented 2 years ago

When using homebrew-virt-manager to link remote hosts, we are always asked to enter passwords frequently. Maybe we can solve this problem through SSH key, but if you are unwilling or unable to solve this problem through SSH key, this method may help you. 使用homebrew-virt-manager 链接远程主机时,总是频繁的要求我们输入密码,或许我们可以通过ssh密钥解决此问题,但如果您不愿意或者无法通过ssh密钥解决此问题时,此方法或许能帮助到您。

You only need to use the python script provided at the end of the article to ask you to enter your password once when starting virt manager. In the future, you will not be asked to enter your password repeatedly. I hope you can do it! 您只需要通过文末提供的python脚本,启动virt-manager时要求您输入一次密码,后续就不会再让您重复的多次输入密码,希望能够办到你!

Before that, you need to make sure that you have Python on your computer and you need to install pexpect through pip 在这之前您需要确保您的电脑上有python,并且需要通过pip安装pexpect

pip3 install pexpect

Then write these contents to a file and rename it KVM Py, or any other name you like, and then start the python script! You may need to copy the file to / usr / local / bin / to ensure that you can quickly use this script in any environment! 然后将这些内容写入到文件,重命名为kvm.py, 或者其他什么您喜欢的名字,而后启动该python脚本即可! 您也许需要将文件复制到/usr/local/bin/, 以确保在任何环境下都可以快捷的使用此脚本!

#!/usr/bin/env python
import pexpect, sys, getpass

args = sys.argv
try:
    passwd = args[1]
except IndexError:
    passwd = getpass.getpass("Password: ")

child = pexpect.spawn('virt-manager')
while True:
    try:
        child.expect('assword')
    except pexpect.exceptions.TIMEOUT:
        pass

    child.sendline(passwd)