[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-100]
don't forget demo_windows.py update MANIFEST.in to include demo_windows.py and not include the demo keys (they're in tests/ now). clean up the README to explain the demo scripts better now, since there are so many of them. then fix up the demo scripts to look in tests/ for the keys. demo_windows.py doesn't need to call get_pty() (in fact, i think that's blowing openssh's mind) and was executing the wrong command.
This commit is contained in:
parent
1d1a60047c
commit
e86c5f0106
|
@ -1,3 +1,3 @@
|
||||||
include ChangeLog LICENSE test.py demo.py demo_simple.py demo_server.py demo_dss_key demo_rsa_key forward.py
|
include ChangeLog LICENSE test.py demo.py demo_simple.py demo_server.py demo_windows.py forward.py
|
||||||
recursive-include docs *
|
recursive-include docs *
|
||||||
recursive-include tests *.py
|
recursive-include tests *.py *.key
|
||||||
|
|
68
README
68
README
|
@ -76,40 +76,58 @@ Valeriy Pogrebitskiy says the best place to look is
|
||||||
|
|
||||||
*** DEMO
|
*** DEMO
|
||||||
|
|
||||||
the demo client (demo.py) is a raw implementation of the normal 'ssh' CLI tool.
|
several demo scripts come with paramiko to demonstrate how to use it. probably
|
||||||
while the paramiko library should work on all platforms, the demo app will only
|
the simplest demo of all is this:
|
||||||
run on posix, because it uses select.
|
|
||||||
|
|
||||||
you can run demo.py with no arguments, or you can give a hostname (or
|
import paramiko, base64
|
||||||
username@hostname) on the command line. if you don't, it'll prompt you for
|
key = paramiko.RSAKey(data=base64.decodestring('AAA...'))
|
||||||
a hostname and username. if you have an ".ssh/" folder, it will try to read
|
t = paramiko.Transport('ssh.example.com')
|
||||||
the host keys from there, though it's easily confused. you can choose to
|
t.connect(username='strongbad', password='thecheat', hostkey=key)
|
||||||
authenticate with a password, or with an RSA or DSS key.
|
chan = t.open_session()
|
||||||
|
chan.exec_command('ls')
|
||||||
|
for line in chan.makefile('r+'):
|
||||||
|
print '... ' + line.strip('\n')
|
||||||
|
chan.close()
|
||||||
|
t.close()
|
||||||
|
|
||||||
the demo app leaves a logfile called "demo.log" so you can see what paramiko
|
...which prints out the results of executing 'ls' on a remote server. (the
|
||||||
logs as it works. but the most interesting part is probably the code itself,
|
host key 'AAA...' should of course be replaced by the actual base64 encoding
|
||||||
which hopefully demonstrates how you can use the paramiko library.
|
of the host key. if you skip host key verification, the connection is not
|
||||||
|
secure!)
|
||||||
|
|
||||||
a simpler example is in demo_simple.py, which is a copy of the demo client
|
the following example scripts get progressively more detailed:
|
||||||
that uses the simpler "connect" method call (new with 0.9-doduo).
|
|
||||||
|
|
||||||
a demo for windows is in demo_windows.py. it executes 'ls' on the remote
|
demo_windows.py
|
||||||
server and prints the results, avoiding terminal i/o and select() (which
|
executes 'ls' on any remote server, loading the host key from your openssh
|
||||||
are missing in windows).
|
key file. (this script works on windows because it avoids using terminal
|
||||||
|
i/o or the 'select' module.) it also creates a logfile 'demo_windows.log'.
|
||||||
|
|
||||||
there's also now a demo server (demo_server.py) which listens on port 2200
|
demo_simple.py
|
||||||
and accepts a login (robey/foo) and pretends to be a BBS, just to demonstrate
|
calls invoke_shell() and emulates a terminal/tty through which you can
|
||||||
how to perform the server side of things.
|
execute commands interactively on a remote server. think of it as a poor
|
||||||
|
man's ssh command-line client. (works only on posix [unix or macosx].)
|
||||||
|
|
||||||
|
demo.py
|
||||||
|
same as demo_simple.py, but allows you to authenticiate using a private
|
||||||
|
key, and uses the long form of some of the API calls. (posix only.)
|
||||||
|
|
||||||
|
forward.py
|
||||||
|
command-line script to set up port-forwarding across an ssh transport.
|
||||||
|
(requires python 2.3 and posix.)
|
||||||
|
|
||||||
|
demo_server.py
|
||||||
|
an ssh server that listens on port 2200 and accepts a login for 'robey'
|
||||||
|
(password 'foo'), and pretends to be a BBS. meant to be a very simple
|
||||||
|
demo of writing an ssh server. (should work on all platforms.)
|
||||||
|
|
||||||
|
|
||||||
*** USE
|
*** USE
|
||||||
|
|
||||||
the demo clients (demo.py, demo_simple.py, and demo_windows.py) and the demo
|
the demo scripts are probably the best example of how to use this package.
|
||||||
server (demo_server.py) are probably the best example of how to use this
|
there is also a lot of documentation, generated with epydoc, in the doc/
|
||||||
package. there is also a lot of documentation, generated with epydoc, in the
|
folder. point your browser there. seriously, do it. mad props to epydoc,
|
||||||
doc/ folder. point your browser there. seriously, do it. mad props to
|
which actually motivated me to write more documentation than i ever would have
|
||||||
epydoc, which actually motivated me to write more documentation than i ever
|
before.
|
||||||
would have before.
|
|
||||||
|
|
||||||
there are also unit tests here:
|
there are also unit tests here:
|
||||||
$ python ./test.py
|
$ python ./test.py
|
||||||
|
|
|
@ -6,11 +6,8 @@ import paramiko
|
||||||
# setup logging
|
# setup logging
|
||||||
paramiko.util.log_to_file('demo_server.log')
|
paramiko.util.log_to_file('demo_server.log')
|
||||||
|
|
||||||
#host_key = paramiko.RSAKey()
|
#host_key = paramiko.RSAKey(filename='tests/test_rsa.key')
|
||||||
#host_key.read_private_key_file('demo_rsa_key')
|
host_key = paramiko.DSSKey(filename='tests/test_dss.key')
|
||||||
|
|
||||||
host_key = paramiko.DSSKey()
|
|
||||||
host_key.read_private_key_file('demo_dss_key')
|
|
||||||
|
|
||||||
print 'Read key: ' + paramiko.util.hexify(host_key.get_fingerprint())
|
print 'Read key: ' + paramiko.util.hexify(host_key.get_fingerprint())
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ def load_host_keys():
|
||||||
|
|
||||||
|
|
||||||
# setup logging
|
# setup logging
|
||||||
paramiko.util.log_to_file('demo.log')
|
paramiko.util.log_to_file('demo_simple.log')
|
||||||
|
|
||||||
# get hostname
|
# get hostname
|
||||||
username = ''
|
username = ''
|
||||||
|
|
|
@ -38,7 +38,7 @@ def load_host_keys():
|
||||||
|
|
||||||
|
|
||||||
# setup logging
|
# setup logging
|
||||||
paramiko.util.log_to_file('demo.log')
|
paramiko.util.log_to_file('demo_windows.log')
|
||||||
|
|
||||||
# get hostname
|
# get hostname
|
||||||
username = ''
|
username = ''
|
||||||
|
@ -81,12 +81,11 @@ try:
|
||||||
t = paramiko.Transport((hostname, port))
|
t = paramiko.Transport((hostname, port))
|
||||||
t.connect(username=username, password=password, hostkey=hostkey)
|
t.connect(username=username, password=password, hostkey=hostkey)
|
||||||
chan = t.open_session()
|
chan = t.open_session()
|
||||||
chan.get_pty()
|
|
||||||
print '*** Here we go!'
|
print '*** Here we go!'
|
||||||
print
|
print
|
||||||
|
|
||||||
print '>>> ls'
|
print '>>> ls'
|
||||||
chan.exec_command('ps auxww')
|
chan.exec_command('ls')
|
||||||
f = chan.makefile('r+')
|
f = chan.makefile('r+')
|
||||||
for line in f:
|
for line in f:
|
||||||
print line.strip('\n')
|
print line.strip('\n')
|
||||||
|
|
Loading…
Reference in New Issue