• paramiko连接windows10详解,远程管理windows服务器


    1、win10安装 OpenSSH

    官网链接:https://docs.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_firstuse

    按住shift键,在某个目录点击鼠标右键,点击打开powershell

    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
    执行命令在里面

     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'))

    3、执行cmd命令,如开启服务

     

  • 相关阅读:
    Eclipse 插件安装、升级和卸载的方法
    Eclipse中Spring插件的安装
    为eclipse离线安装hibernate tools插件
    Eclipse中Hibernate插件的安装
    Nginx安装配置
    app自动更新(android)
    PhoneGap应用图标icon和启动页面SplashScreen
    highcharts图表的图例legend
    安装android的sdk
    设置全屏
  • 原文地址:https://www.cnblogs.com/machangwei-8/p/15215092.html
Copyright © 2020-2023  润新知