-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_libssh.py
More file actions
executable file
·33 lines (30 loc) · 966 Bytes
/
client_libssh.py
File metadata and controls
executable file
·33 lines (30 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
# sudo apt install python3-pip && pip3 install ansible-pylibssh — sorry
from pylibsshext.session import Session
from pylibsshext.errors import LibsshSessionException
from pylibsshext import __libssh_version__
import sys
import logging
if len(sys.argv) > 2:
print("Usage %s [port=22]" % sys.argv[0], file=sys.stderr)
sys.exit(64)
elif len(sys.argv) > 1:
port = int(sys.argv[1])
else:
port = 22
print("Attempting to establish an SSH connection to localhost:%u..." % port)
print(f'{__libssh_version__=}')
ssh = Session()
ssh.set_log_level(logging.CRITICAL) # CRITICAL is actually mapped to libssh.SSH_LOG_TRACE (…!)
try:
ssh.connect(
host="localhost",
user="root",
password="sekreet",
timeout=2,
port=port,
look_for_keys=False,
host_key_checking=False
)
except LibsshSessionException as e:
print(f'Failed to connect to localhost:{port} over SSH: {e!s}')