V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
YOOHUU
V2EX  ›  Python

Python paramiko 怎么输入交互式的密码?

  •  
  •   YOOHUU · Dec 20, 2018 · 5548 views
    This topic created in 2686 days ago, the information mentioned may be changed or developed.

    要对华为的 IBMC 更改密码,官方文档只给了这么一个流程 Fr1TgA.jpg

    https://s1.ax1x.com/2018/12/20/Fr1TgA.jpg

    搜索了下交互输入就只有这个 s.exec_command('su -root') stdin.write('password') stdin.flush()

    自己参考改了就是各种没反应... 或者报错

    求教

    Supplement 1  ·  Dec 21, 2018
    ![Fs3SSJ.jpg]( https://s1.ax1x.com/2018/12/21/Fs3SSJ.jpg)

    最后用以上方法解决,不过这 API 有点看不懂...
    到底是 send 里面开始输入
    还是在 while 循环里面开始输入,
    试了下把 while 里面的拆出来拼接到 send 下面就不能交互了......

    各位老哥的推荐都看了来着...
    不过要 linux 环境我就没法折腾了...
    Supplement 2  ·  Dec 21, 2018

    Fs3SSJ.jpg

    最后用以上方法解决,不过这 API 有点看不懂... 到底是 send 里面开始输入 还是在 while 循环里面开始输入, 试了下把 while 里面的拆出来拼接到 send 下面就不能交互了......

    各位老哥的推荐都看了来着... 不过要 linux 环境我就没法折腾了...

    YOOHUU
        1
    YOOHUU  
    OP
       Dec 20, 2018
    下班跑路顺手顶一下
    xpresslink
        2
    xpresslink  
       Dec 20, 2018   ❤️ 1
    调用 expect 来交互
    littlewey
        3
    littlewey  
       Dec 20, 2018 via iPhone   ❤️ 1
    pyexpect

    调 shell 用 sshpass
    YOOHUU
        4
    YOOHUU  
    OP
       Dec 20, 2018
    谢楼上各位,明天试试
    leoleoasd
        5
    leoleoasd  
       Dec 20, 2018
    少个\n 吧...
    YOOHUU
        6
    YOOHUU  
    OP
       Dec 20, 2018
    @leoleoasd 你说的这可能性我也试了,凉凉
    ThirdFlame
        7
    ThirdFlame  
       Dec 20, 2018   ❤️ 1
    passwd 修改密码可以这样,你可以参照修改下试试
    stdin, stdout, stderr = ssh_client.exec_command("passwd", timeout = 10)
    stdin.write("{0}\n{1}\n{1}\n".format(old_password, new_password))
    out,err = stdout.read(),stderr.read()
    YOOHUU
        8
    YOOHUU  
    OP
       Dec 20, 2018
    @ThirdFlame 好的,我明天测试
    4linuxfun
        9
    4linuxfun  
       Dec 20, 2018
    可以试试 fabric,又 watcher,可以类似 pexpect 进行正则匹配后输入信息
    YOOHUU
        10
    YOOHUU  
    OP
       Dec 20, 2018
    @4linuxfun 现在还没涉及到你所说的功能...能输入就 ko 了
    julyclyde
        11
    julyclyde  
       Dec 21, 2018
    stdin 和 tty 不同的
    ssh 是从 tty 读取密码的
    YOOHUU
        12
    YOOHUU  
    OP
       Dec 21, 2018
    @julyclyde 萌新不太清楚这个,学习了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   968 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 20:41 · PVG 04:41 · LAX 13:41 · JFK 16:41
    ♥ Do have faith in what you're doing.