pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.91k stars 382 forks source link

Does not work with encrypted SSH keys on macos 12.2 #747

Closed anbsky closed 2 years ago

anbsky commented 2 years ago

Describe the bug

Pyinfra is unable to connect when authenticating with an SSH key. Supplying or ommitting ssh_key_password in the inventory or as a cli argument does not change the behavior in any way.

--> Loading config...
--> Loading inventory...

--> Connecting to hosts...
    [myhost.com] Authentication error (username=my_user) (Private key file is encrypted)
--> pyinfra error: No hosts remaining!

To Reproduce

inventory.py:

my_hosts = [
    ('myhost.com', {'ssh_user': 'my_user', 'ssh_key_password': '<password>'}),
]

deploy.py:

from pyinfra.operations import server

server.shell(
    name='Run an ad-hoc command',  # optional name for the operation
    commands='echo "hello world"',
)

pyinfra inventory.py deploy.py

Meta

PIP-installed.

--> Support information:

    If you are having issues with pyinfra or wish to make feature requests, please
    check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
    When adding an issue, be sure to include the following:

    System: Darwin
      Platform: macOS-12.2-arm64-arm-64bit
      Release: 21.3.0
      Machine: arm64
    pyinfra: v1.6.1
    Executable: /opt/homebrew/bin/pyinfra
    Python: 3.9.9 (CPython, Clang 13.0.0 (clang-1300.0.29.3))
Fizzadar commented 2 years ago

Hi @andybeletsky - could you try with specifying the key directly, ie ssh_key: '/path/to/key'. You should get a prompt for the password.

Are you using an SSH agent? I think the issue here is when a key isn't explicitly provided the password flow isn't followed, which should only happen if a key is found on disk (by default pyinfra will look for agent + keys if none provided).

Fizzadar commented 2 years ago

Closing pending furhter information, happy to reopen with more info :)