Comments (1)
Thanks for the feedback! See my response below.
Most users don't have localhost included in ~/.ssh/known_hosts. Suggestion: state this requirement
If you take a look at https://asyncssh.readthedocs.io/en/stable/#client-examples, it currently says the following just above the first example:
The following code shows an example of a simple SSH client which logs into localhost and
lists files in a directory named ‘abc’ under the user’s home directory. The username provided
is the logged in user, and the user’s default SSH client keys or certificates are presented during
authentication. The server’s host key is checked against the user’s SSH known_hosts file and
the connection will fail if there’s no entry for localhost there or if the key doesn’t match.
Was there something more you were looking for here? I could add a sentence around running "ssh localhost" to get the key added, but my expectation is that most AsyncSSH users are already familiar with the basics of SSH, like how user authentication and server host key checking works. Also, without knowing the config of OpenSSH on the system, I can't count on ssh localhost
always prompting to add a server host key to known_hosts.
I intentionally avoided including known_hosts=None
to disable host key checking in the example as I didn't want to encourage insecure behavior. I wanted it to fail if the server host key wasn't trusted.
This is because the example used runs the remote command: ls abc and most users won't realize (without some work) that this command fails unless there is a file or directory in their home directory on the remote machine named 'abc'.
You're right that I could have used a command which would be less likely to fail, like hostname
. The text above the example clearly states what the command is attempting to do, though, and I chose that in part so that there would be a chance it could fail, triggering a Python exception rather than just outputting an error back on stderr. Note that this example includes the check=True
argument, which is what triggers it to turn the failure into an exception.
That said, the example doesn't do a very good job explaining what comes back. The current output is something like:
SSH connection failed: Process exited with non-zero exit status 1
I could have the example catch the exception in conn.run()
explicitly, and have it print out exc.stderr
instead of result.stdout
. It makes the example a bit longer, but it could be worth it to make it clearer what's going on. For example:
import asyncio, asyncssh, sys
async def run_client() -> None:
async with asyncssh.connect('localhost') as conn:
try:
result = await conn.run('ls abc', check=True)
except asyncssh.ProcessError as exc:
print(exc.stderr, end='')
print(f'Process exited with status {exc.exit_status}', file=sys.stderr)
else:
print(result.stdout, end='')
try:
asyncio.run(run_client())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH connection failed: ' + str(exc))
What do you think?
from asyncssh.
Related Issues (20)
- Asyncssh for docker run HOT 3
- Setting terminal size of a sub process HOT 28
- v2.14.2 has interop problem with netdev running with python 3.8 HOT 3
- AsyncSSH Connection to Cisco Router with Jump Host HOT 6
- Why is the loop waiting for command execution endless? HOT 2
- asyncssh raises ValueError if `SetEnv` is used in SSH config HOT 13
- 2.14.1+ fails to rekey with OpenSSH <= 6 HOT 7
- asyncio.run(asyncssh.connect()) raises ValueError: a coroutine was expected, got <asyncssh.misc._ACMWrapper object ..> HOT 4
- OOM when redirecting large stdout to asyncio Process HOT 11
- SFTP preserve always follows symlinks HOT 5
- Allow host key rotation, implement [email protected] / [email protected] request HOT 8
- Logging error in SFTP copy with `Sequence[PurePath]` HOT 4
- Intermittent failure to read output when using SSHClientProcess.wait HOT 6
- Suppress deprecation warnings from Cyrptography 43.0.0 when importing ARC4 and TripleDES HOT 7
- Parsing breaks ProxyCommand executable path on Windows. HOT 8
- SSH connection issue when upgrading to asyncssh 2.15.0 HOT 16
- The handle is invalid HOT 7
- GSSAPI limited to single user principal HOT 5
- Spurious calls to `SSHChannel._cleanup` starting from AsyncSSH 2.15.0 HOT 3
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 asyncssh.