AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 401408
Accepted
Banjer
Banjer
Asked: 2012-06-23 10:05:25 +0800 CST2012-06-23 10:05:25 +0800 CST 2012-06-23 10:05:25 +0800 CST

在 Fabric 中使用 /etc/ssh 中的 SSH 配置和密钥

  • 772

我正在尝试将 SSH 密钥与 Fabric 一起使用,而不是每次运行时都必须输入密码fab。我们所有的主机都共享同一个/etc/ssh/ssh_known_hosts文件,其中包含它们所有的公共 rsa 密钥,而且我能够在没有密码的情况下从一台主机到另一台主机进行 SSH。

我必须遵循我的环境变量设置fabfile.py:

env.use_ssh_config = True
env.ssh_config_path = '/etc/ssh/ssh_config'
env.key_filename = '/etc/ssh/ssh_host_rsa_key'

我fab test以 root 身份运行一个简单的命令:

def test:
    run('uname -s')

我已经浏览了所有文档并进行了大量搜索,但我没有看到使用密钥和配置的示例/etc/ssh;这些示例通常展示如何使用 configs 和 keys in ~/.ssh/,所以我可能误解了如何使用这些设置。

这是一个调试:

root@beef:~> fab test
[chicken] Executing task 'test'
[chicken] run: uname -s
DEBUG:ssh.transport:starting thread (client mode): 0x141c710L
INFO:ssh.transport:Connected (version 1.99, client OpenSSH_5.1)
DEBUG:ssh.transport:kex algos:['diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss'] client encrypt:['aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 'aes192-cbc', 'aes256-cbc', '[email protected]', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr'] server encrypt:['aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'arcfour128', 'arcfour256', 'arcfour', 'aes192-cbc', 'aes256-cbc', '[email protected]', 'aes128-ctr', 'aes192-ctr', 'aes256-ctr'] client mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5', 'hmac-sha1', '[email protected]', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', '[email protected]', 'zlib'] server compress:['none', '[email protected]', 'zlib'] client lang:[''] server lang:[''] kex follows?False
DEBUG:ssh.transport:Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEBUG:ssh.transport:using kex diffie-hellman-group1-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
DEBUG:ssh.transport:Switch to new keys ...
DEBUG:ssh.transport:Adding ssh-rsa host key for chicken: 56f3f71a494013976c183844d342ed1b
[chicken] Login password for 'root':

系统日志chicken说

Jun 22 13:48:47 chicken sshd[7328]:未收到来自 172.xxx 的标识字符串

所以我没有传递正确的密钥文件或其他东西......

更新

我从 Fabric 用户邮件列表收到了一些故障排除提示。

我可以看到,当我从 shell 连接到 ssh 客户端时,客户端请求连接方法为“无”,然后是“基于主机”。Fabric(或 Paramiko)似乎立即请求公钥。请注意每个示例中选择的连接方法:

登录成功

root@beef:~> ssh -t -i /etc/ssh/ssh_host_rsa_key chicken uname -s

root@chicken:~> /usr/sbin/sshd -d
...snip...
debug1: userauth-request for user root service ssh-connection method none
debug1: attempt 0 failures 0
debug1: PAM: initializing for "root"
debug1: userauth-request for user root service ssh-connection method hostbased
debug1: attempt 1 failures 0
debug1: userauth_hostbased: cuser root chost beef. pkalg ssh-dss slen 55
debug1: PAM: setting PAM_RHOST to "beef"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: fd 4 clearing O_NONBLOCK
debug1: restore_uid: 0/0
Failed hostbased for root from 172.x.x.x port 54623 ssh2
debug1: userauth-request for user root service ssh-connection method hostbased
debug1: attempt 2 failures 1
debug1: userauth_hostbased: cuser root chost beef. pkalg ssh-rsa slen 271
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: fd 4 clearing O_NONBLOCK
debug1: restore_uid: 0/0
debug1: ssh_rsa_verify: signature correct
debug1: do_pam_account: called
Accepted hostbased for root from 172.x.x.x port 54623 ssh2

通过 Fabric 登录失败

root@beef:~ > fab test

root@chicken:~> /usr/sbin/sshd -d
...snip...
debug1: userauth-request for user root service ssh-connection method publickey
debug1: attempt 0 failures 0
debug1: PAM: initializing for "root"
debug1: PAM: setting PAM_RHOST to "beef"
debug1: PAM: setting PAM_TTY to "ssh"
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: trying public key file /root/.ssh/authorized_keys
debug1: restore_uid: 0/0
debug1: temporarily_use_uid: 0/0 (e=0/0)
debug1: trying public key file /root/.ssh/authorized_keys2
debug1: restore_uid: 0/0
Failed publickey for root from 172.x.x.x port 54630 ssh2

所以...问题:有什么方法可以将 hostbased 指定为 Fabric/Paramiko 中的首选连接方法?

linux ssh fabric
  • 1 1 个回答
  • 3378 Views

1 个回答

  • Voted
  1. Best Answer
    Banjer
    2012-07-10T07:46:13+08:002012-07-10T07:46:13+08:00

    这里的部分问题是我对公钥与基于主机的身份验证的混淆。不过,我确实问过 Fabric 邮件列表这个问题:

    有什么方法可以将 hostbased 指定为首选连接方法?是否可以在我的 fabfile 中设置 Paramiko 设置?

    其中一位作者回应道:

    我不认为 Paramiko 支持基于主机的,虽然它最初不是我的库所以我可能是错的。当然,除了给它一个密钥之外,Fabric 并没有告诉它是基于密钥的(即在 client.connect() 中没有明显的“要尝试的身份验证方案列表”设置)。

    Paramiko 是 Fabric 使用的 python SSH 模块。所以,看起来没有办法在 Fabric/Paramiko 中设置首选的身份验证方案。我决定最好在我的 fabfile 中运行我的命令,而不是尝试以fabroot 身份运行并且不提示输入密码,这样我就可以在. 无论如何,这要求我将我的 sudo 密码作为参数传递。sudo()/var/log/sudo.log

    • 0

相关问题

  • 多操作系统环境的首选电子邮件客户端

  • 你最喜欢的 Linux 发行版是什么?[关闭]

  • 更改 PHP 的默认配置设置?

  • 保护新的 Ubuntu 服务器 [关闭]

  • (软)Ubuntu 7.10 上的 RAID 6,我应该迁移到 8.10 吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve