Comments (5)
Hello,
I've had some problems with the demos too, but I got this one working with:
host.encode('utf-8')
from ssh2-python.
@JoelStienlet Thanks for the info, I tried but I am getting the same result regardless of the encoding of the hostname:
Read 3 hosts from known hosts file at /root/.ssh/known_hosts
Traceback (most recent call last):
File "test.py", line 34, in <module>
kh.checkp(host.encode('utf-8'), 22, host_key, type_mask)
File "ssh2/knownhost.pyx", line 252, in ssh2.knownhost.KnownHost.checkp
ssh2.exceptions.KnownHostCheckNotFoundError: ('Host %s not found in known hosts collection', b'localhost')
I of course made sure that the host is in the known_hosts file so it should find it no problem.
>grep localhost ~/.ssh/known_hosts
localhost ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAVsEAljGvdqAwiyTaUPJZTHu0XVRby+M/2HttiaagThlLmgA8asBMzHNkXnOJO6hJXS2VZZDgwGv1XFr2yH+CA=
Sure it does not complain but the code still does not quite work... going to spend quite some more time on this trying to work out what is wrong as I am not very familiar with the underlying library its hard to debug this one
from ssh2-python.
Can you check the value of type_mask? I've used LIBSSH2_KNOWNHOST_TYPE_PLAIN:
from ssh2.knownhost import LIBSSH2_KNOWNHOST_TYPE_PLAIN
kh.checkp(args.host.encode('utf-8'), args.port, host_key, LIBSSH2_KNOWNHOST_TYPE_PLAIN )
from ssh2-python.
Hi there,
Thanks for the interest and report.
The example script is correct.
The reason it does not work for the above is because the key type in the hosts file is ecdsa-sha2-nistp256
while the example script tries to verify RSA or DSS keys. The underlying library is low level and requires explicit key type checks.
Python version does not matter, though the host parameter must be in bytes - b'localhost'
- currently. It could take unicode as well for ease of use, though unicode characters in known host files are not valid.
The exception is because a matching host and key type cannot be found - there can be multiple keys per host of different types. On type check errors where a host does match the error returned is KnownHostCheckNotFoundError
regardless.
There is now ECDSA and ED25519 key type support in libssh2, neither of which have flags exposed in ssh2.knownhost
. The example script might also check for all possible key types.
PRs welcome for both of these.
from ssh2-python.
Flags updated for latest libssh2. Examples welcome.
from ssh2-python.
Related Issues (20)
- Unknown error while starting the session HOT 1
- Fails to build on Python 3.11 - longintrepr.h: No such file or directory HOT 1
- ssh2-python is unable to establish connection with RHEL 9 SSHD HOT 2
- Remove Python 2 support badge HOT 1
- ed25519 key auth fails with FileError HOT 7
- `SocketRecvError` on resuming upload of partially uploaded files HOT 2
- Update libssh2 version to 1.11.0 HOT 8
- Help installing ssh2-python on alpine docker container HOT 1
- ssh2-python failed to install on windows 11 python 3.11, python 3.10 install succeded HOT 1
- Unable to install on python 3.10 macOS M1 HOT 2
- [Feature request] Musllinux wheel
- Python 3.12 support HOT 1
- Feature request: enable compression flag HOT 3
- Drop EOL Python versions (3.6, 3.7)
- Drop manylinux2010 wheels
- Migrate to OpenSSL 3
- Migrate to Cython 3
- Automate updating of vendored libraries
- scp does not write to file
- Core dump when calling session.methods()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ssh2-python.