Merge pull request #22 from catskul/catskul/sshagent
feat: option to use ssh agent
This commit is contained in:
@@ -15,7 +15,7 @@ pip install remarkable-mouse
|
||||
remouse
|
||||
```
|
||||
|
||||
By default, `10.11.99.1` is used as the address. Seems to work pretty well wirelessly, too.
|
||||
By default, `10.11.99.1` is used as the address. Seems to work pretty well wirelessly, too. By default ssh-agent is used to authenticate if it is available, otherwise you are asked for your password.
|
||||
|
||||
# Examples
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import struct
|
||||
from getpass import getpass
|
||||
|
||||
import paramiko
|
||||
import paramiko.agent
|
||||
|
||||
logging.basicConfig(format='%(message)s')
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -27,6 +28,14 @@ def open_remote_device(args, file='/dev/input/event0'):
|
||||
"""
|
||||
log.info("Connecting to input '{}' on '{}'".format(file, args.address))
|
||||
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
|
||||
pkey = None
|
||||
password = None
|
||||
|
||||
agent = paramiko.agent.Agent()
|
||||
|
||||
if args.key is not None:
|
||||
password = None
|
||||
try:
|
||||
@@ -42,14 +51,12 @@ def open_remote_device(args, file='/dev/input/event0'):
|
||||
elif args.password:
|
||||
password = args.password
|
||||
pkey = None
|
||||
else:
|
||||
elif not agent.get_keys():
|
||||
password = getpass(
|
||||
"Password for '{}': ".format(args.address)
|
||||
)
|
||||
pkey = None
|
||||
|
||||
client = paramiko.SSHClient()
|
||||
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
client.connect(
|
||||
args.address,
|
||||
username='root',
|
||||
@@ -58,6 +65,10 @@ def open_remote_device(args, file='/dev/input/event0'):
|
||||
look_for_keys=False
|
||||
)
|
||||
|
||||
session = client.get_transport().open_session()
|
||||
|
||||
paramiko.agent.AgentRequestHandler(session)
|
||||
|
||||
# Start reading events
|
||||
_, stdout, _ = client.exec_command('cat ' + file)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user