Skip to content

Commit ff56ca5

Browse files
committed
一个ssh登录测试
1 parent 7492021 commit ff56ca5

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
File renamed without changes.

basic/os/sshlogin.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
"""
4+
Topic: paramiko模块演示
5+
https://github.com/paramiko/paramiko/tree/master/demos
6+
7+
安装python3-pycrypto-windows
8+
python3.4版本之前:http://www.voidspace.org.uk/python/modules.shtml#pycrypto
9+
python3.4最新版本:https://github.com/axper/python3-pycrypto-windows-installer
10+
11+
先安装Visual C++ 2010 Express,这个是免费的:
12+
http://www.visualstudio.com/zh-cn/downloads/download-visual-studio-vs#DownloadFamilies_4
13+
14+
安装后可以先试着pip install paramiko看能不能成功,如果还不行就再下载下面的:
15+
如果安装上面的最后提示还有个SQL Server 2008 Express Service Pack1没安装成功,那么自己手动去下载安装:
16+
http://www.microsoft.com/zh-tw/download/details.aspx?id=25052
17+
18+
pip install paramiko
19+
"""
20+
import paramiko
21+
22+
if __name__ == '__main__':
23+
server = '192.168.203.95'
24+
username = 'root'
25+
password = 'root'
26+
ssh = paramiko.SSHClient()
27+
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
28+
ssh.connect(server, username=username, password=password)
29+
# channel = ssh.invoke_shell()
30+
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('/home/mango/work/update.sh')
31+
for eline in ssh_stdout.readlines():
32+
print('ssh_stdout:{}'.format(eline), end='')
33+
for eline in ssh_stderr.readlines():
34+
print('ssh_stderr:{}'.format(eline), end='')
35+
# Cleanup
36+
ssh_stdin.close()
37+
ssh_stdout.close()
38+
ssh_stderr.close()
39+
40+
# channel.close()
41+
ssh.close()
42+

0 commit comments

Comments
 (0)