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
fxxkgw
V2EX  ›  Python

paramiko connect 时候遇到的问题。

  •  
  •   fxxkgw · Oct 25, 2016 · 4325 views
    This topic created in 3471 days ago, the information mentioned may be changed or developed.

    如果 Linux 服务器密码过期了, ssh 时候会有下面提示:

    You are required to change your password immediately (password aged)
    WARNING: Your password has expired.
    You must change your password now and login again!
    Changing password for user XX.
    Changing password for XX.
    (current) UNIX password: ###卡在这里等着输入密码
    
    当用 python 的 paramiko 模块通过用户名 密码登录时
    s = paramiko.SSHClient()
    s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    s.connect(host,port,user,pwd)###这个地方并没有任何报错
    s.exec_command(cmd, get_pty=True, timeout=500) #这个地方因为密码过期了,会卡住直到超时报错
    
    现在想在 s.connect 这个地方做个检测,如果碰到密码过期就返回错误,翻了参数也没发现有控制的地方,请教有什么好的处理方式么。
    
    2 replies    2016-10-28 07:30:29 +08:00
    KIDJourney
        1
    KIDJourney  
       Oct 26, 2016
    exec_command 的时候把 stdin 和 stdout 拿出来,读一下 stdout ,密码过期的话用把新密码打到 stdin 里就行。

    参见[How to sudo in para]( http://stackoverflow.com/questions/6270677/how-to-run-sudo-with-paramiko-python)
    eyp82
        2
    eyp82  
       Oct 28, 2016
    我觉得配置 ssh 无密码登陆不是更好一些? 不需要你脚本里记录密码, 另外也不需要考虑密码过期的问题了.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4822 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 01:05 · PVG 09:05 · LAX 18:05 · JFK 21:05
    ♥ Do have faith in what you're doing.