天天看點

paramiko連接配接windows10詳解,遠端管理windows伺服器

1、win10安裝 OpenSSH

官網連結:https://docs.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_firstuse

按住shift鍵,在某個目錄點選滑鼠右鍵,點選打開powershell

paramiko連接配接windows10詳解,遠端管理windows伺服器
paramiko連接配接windows10詳解,遠端管理windows伺服器
1、安裝軟體
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

2、啟動軟體
# Start the sshd service
Start-Service sshd

# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'

# Confirm the firewall rule is configured. It should be created automatically by setup.
Get-NetFirewallRule -Name *ssh*

# There should be a firewall rule named "OpenSSH-Server-In-TCP", which should be enabled
# If the firewall does not exist, create one
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

3、解除安裝軟體
# Uninstall the OpenSSH Client
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Uninstall the OpenSSH Server
Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0      

執行指令在裡面

paramiko連接配接windows10詳解,遠端管理windows伺服器
paramiko連接配接windows10詳解,遠端管理windows伺服器
paramiko連接配接windows10詳解,遠端管理windows伺服器

 2、連接配接windows程式

import paramiko
ssh = paramiko.SSHClient()

ssh.load_system_host_keys()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect('192.168.*.*',port = 22, username='ADMINISTRATOR',password='****')

print ("Connected to %s" % '192.168.*.*')

stdin, stdout, stderr = ssh.exec_command('dir d:')
aa=stdout.read()
bb=stderr.read()
print(aa.decode('gbk'))
print('==========================')
print(bb.decode('gbk'))      
paramiko連接配接windows10詳解,遠端管理windows伺服器
paramiko連接配接windows10詳解,遠端管理windows伺服器

3、執行cmd指令,如開啟服務

paramiko連接配接windows10詳解,遠端管理windows伺服器
paramiko連接配接windows10詳解,遠端管理windows伺服器

 4、運作wmic指令

windows cmd指令學習:https://www.cnblogs.com/machangwei-8/p/10859951.html

ip='127.0.0.1'
ssh.connect(ip,port = 22, username='ADMINISTRATOR',password='m1xxx')      
paramiko連接配接windows10詳解,遠端管理windows伺服器
上一篇: ss指令詳解
下一篇: nmap指令詳解