Secure Shell

Table of Contents

Login ssh

# ssh [email protected] "uname"

from paramiko.client import SSHClient
with SSHClient() as ssh:
    ssh.connect("localhost", username="me", password="pwd")
    stdin, stdout, stderr = ssh.exec_command("uname")
    print(stdout.read())
# ssh -p 2222 [email protected] "uname"

from paramiko.client import SSHClient
with SSHClient() as ssh:
    ssh.connect("localhost", 2222, username="me", password="pwd")
    stdin, stdout, stderr = ssh.exec_command("uname")
    print(stdout.read())
# ignore known hosts
# ssh -o StrictHostKeyChecking=no \
#     -o UserKnownHostsFile=/dev/null \
#     [email protected] "uname"

import paramiko
from paramiko.client import SSHClient
with SSHClient() as ssh:
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect("localhost", username="me", password="pwd")
    stdin, stdout, stderr = ssh.exec_command("uname")
    print(stdout.read())
# ssh-keygen -f key -m pem -t rsa
# ssh-copy-id -i key [email protected]
# ssh -i key [email protected] "uname"

with SSHClient() as ssh:
    ssh.connect('localhost', username="me", key_filename="key")
    stdin, stdout, stderr = ssh.exec_command("uname")
    print(stdout.read())
# ssh-keygen -m pem -f key -t rsa -P passphrase
# eval $(ssh-agent)
# ssh-add key
# ssh -i key [email protected]