Fabric 以前可以使用 ssh-keys,但现在不再可以使用了

Fabric 以前可以使用 ssh-keys,但现在不再可以使用了

我已经正确设置了 ssh 密钥,并且可以无需密码通过 ssh 进入远程机器。

然而,几个小时前,我的结构部署脚本可以自动进行身份验证,每当我尝试部署到远程机器时,它就会开始要求我输入私钥密码。

即使我输入了密码,它似乎也不关心我是否输入了正确的密码,并会提示系统登录,就好像我根本没有 ssh 密钥一样。

请记住,我是一名开发人员,而不是系统工程师,不熟悉 Fabric 的工作原理。我很可能遗漏了一些显而易见的东西。任何解决方案,甚至是寻找方向的指示都将不胜感激。

这是我从实际部署脚本中衍生出来的校对脚本:

#!/usr/bin/env python2

import sys
from fabric.api import *
from fabric.network import ssh

ssh.util.log_to_file("paramiko.log", 10)

@hosts(['host-ip-address'])

def boot():
    env.use_ssh_config = True
    env.user = 'userlogin'
    env.key_filename = ['~/.ssh/some-public-key.pem']
    env.gateway = '[email protected]'
    execute(a)

def a():
    run('ls')

boot()

以下是来自 paramiko 的日志消息:

DEB [20141007-19:22:50.804] thr=1   paramiko.transport: starting thread (client mode): 0xfe2790L
INF [20141007-19:22:50.847] thr=1   paramiko.transport: Connected (version 2.0, client OpenSSH_6.2)
DEB [20141007-19:22:50.856] thr=1   paramiko.transport: kex algos:[u'ecdh-sha2-nistp256', u'ecdh-sha2-nistp384', u'ecdh-sha2-nistp521', u'diffie-hellman-group-exchange-sha256', u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa', u'ssh-dss', u'ecdsa-sha2-nistp256'] client encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'[email protected]', u'[email protected]', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'[email protected]'] server encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'[email protected]', u'[email protected]', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'[email protected]'] client mac:[u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'hmac-md5', u'hmac-sha1', u'[email protected]', u'[email protected]', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-ripemd160', u'[email protected]', u'hmac-sha1-96', u'hmac-md5-96'] server mac:[u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'hmac-md5', u'hmac-sha1', u'[email protected]', u'[email protected]', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-ripemd160', u'[email protected]', u'hmac-sha1-96', u'hmac-md5-96'] client compress:[u'none', u'[email protected]'] server compress:[u'none', u'[email protected]'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20141007-19:22:50.856] thr=1   paramiko.transport: Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEB [20141007-19:22:50.856] thr=1   paramiko.transport: using kex diffie-hellman-group14-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEB [20141007-19:22:50.903] thr=1   paramiko.transport: Switch to new keys ...
DEB [20141007-19:22:50.907] thr=2   paramiko.transport: Trying key 3433922e6c7bef8672043fbfe07c22f3 from /Users/ganeshwara/.dme/sg-master.pem
DEB [20141007-19:22:50.954] thr=1   paramiko.transport: userauth is OK
INF [20141007-19:22:51.033] thr=1   paramiko.transport: Authentication (publickey) failed.
DEB [20141007-19:22:51.040] thr=2   paramiko.transport: Trying SSH agent key f8f4822cc3d40df79b9f7c79f219c42c
DEB [20141007-19:22:51.045] thr=1   paramiko.transport: userauth is OK
INF [20141007-19:22:51.061] thr=1   paramiko.transport: Authentication (publickey) failed.
DEB [20141007-19:22:51.704] thr=3   paramiko.transport: starting thread (client mode): 0xff0a10L
INF [20141007-19:22:51.723] thr=3   paramiko.transport: Connected (version 2.0, client OpenSSH_6.2)
DEB [20141007-19:22:51.728] thr=3   paramiko.transport: kex algos:[u'ecdh-sha2-nistp256', u'ecdh-sha2-nistp384', u'ecdh-sha2-nistp521', u'diffie-hellman-group-exchange-sha256', u'diffie-hellman-group-exchange-sha1', u'diffie-hellman-group14-sha1', u'diffie-hellman-group1-sha1'] server key:[u'ssh-rsa', u'ssh-dss', u'ecdsa-sha2-nistp256'] client encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'[email protected]', u'[email protected]', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'[email protected]'] server encrypt:[u'aes128-ctr', u'aes192-ctr', u'aes256-ctr', u'arcfour256', u'arcfour128', u'[email protected]', u'[email protected]', u'aes128-cbc', u'3des-cbc', u'blowfish-cbc', u'cast128-cbc', u'aes192-cbc', u'aes256-cbc', u'arcfour', u'[email protected]'] client mac:[u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'hmac-md5', u'hmac-sha1', u'[email protected]', u'[email protected]', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-ripemd160', u'[email protected]', u'hmac-sha1-96', u'hmac-md5-96'] server mac:[u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'[email protected]', u'hmac-md5', u'hmac-sha1', u'[email protected]', u'[email protected]', u'hmac-sha2-256', u'hmac-sha2-512', u'hmac-ripemd160', u'[email protected]', u'hmac-sha1-96', u'hmac-md5-96'] client compress:[u'none', u'[email protected]'] server compress:[u'none', u'[email protected]'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20141007-19:22:51.728] thr=3   paramiko.transport: Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEB [20141007-19:22:51.728] thr=3   paramiko.transport: using kex diffie-hellman-group14-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEB [20141007-19:22:51.799] thr=3   paramiko.transport: Switch to new keys ...
DEB [20141007-19:22:51.806] thr=2   paramiko.transport: Trying key 3433922e6c7bef8672043fbfe07c22f3 from /Users/ganeshwara/.dme/sg-master.pem
DEB [20141007-19:22:51.848] thr=3   paramiko.transport: userauth is OK
INF [20141007-19:22:51.932] thr=3   paramiko.transport: Authentication (publickey) failed.
DEB [20141007-19:22:51.938] thr=2   paramiko.transport: Trying SSH agent key f8f4822cc3d40df79b9f7c79f219c42c
DEB [20141007-19:22:51.943] thr=3   paramiko.transport: userauth is OK
INF [20141007-19:22:51.955] thr=3   paramiko.transport: Authentication (publickey) failed.
DEB [20141007-19:22:51.979] thr=3   paramiko.transport: userauth is OK
DEB [20141007-19:22:51.984] thr=3   paramiko.transport: Authentication type (password) not permitted.
DEB [20141007-19:22:51.985] thr=3   paramiko.transport: Allowed methods: [u'publickey']
DEB [20141007-19:22:52.717] thr=1   paramiko.transport: EOF in transport thread
DEB [20141007-19:22:52.794] thr=3   paramiko.transport: EOF in transport thread

编辑:

我的~/.ssh/config

Host gateway
 HostName gateway.com
 User user
 Port 22
 IdentityFile ~/.ssh/some-public-key.pem

Host remote-machine
 HostName host-ip-address
 User userlogin
 IdentityFile ~/.ssh/remote-machine.pem
 ProxyCommand ssh gateway -W %h:%p

我想澄清一下,在我的本地机器上,我确实可以成功连接到远程机器,如下所示:

# ssh remote-machine

答案1

我发现了这个问题。

我必须重新添加所有密钥,例如ssh-add <path/to/key.pem>重新启动计算机。

此主题解释所需的配置,这样您不必在每次重新启动机器时重新添加密钥。

相关内容