ÔõÑùʹÓÃÇå¾²µÄÔ¶³Ì×ÀÃæÐÒ飨RDP£©À´»á¼ûCentOSЧÀÍÆ÷
ÔõÑùʹÓÃÇå¾²µÄÔ¶³Ì×ÀÃæÐÒ飨rdp£©À´»á¼ûcentosЧÀÍÆ÷
Ô¶³Ì×ÀÃæÐÒ飨RDP£©ÊÇÒ»ÖÖÓÃÓÚÔ¶³Ì¿ØÖÆÅÌËã»úµÄÐÒ飬ÆÕ±éÓ¦ÓÃÓÚWindows²Ù×÷ϵͳÉÏ¡£¿ÉÊǹØÓÚCentOSЧÀÍÆ÷À´Ëµ£¬Ä¬Èϲ¢²»Ö§³ÖRDPÐÒé¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùʹÓÃÇå¾²µÄRDPÐÒéÀ´»á¼ûCentOSЧÀÍÆ÷£¬²¢ÌṩÏà¹ØµÄ´úÂëʾÀý¡£
×°ÖÃxrdpЧÀÍ
Ê×ÏÈ£¬ÎÒÃÇÐèҪװÖÃÒ»¸öÃûΪxrdpµÄÈí¼þ°ü£¬Ëü¿ÉÒÔʵÏÖÔÚCentOSЧÀÍÆ÷ÉÏÖ§³ÖRDPÐÒé¡£ÔÚÖÕ¶ËÖÐÖ´ÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃxrdpЧÀÍ£º
sudo yum install xrdp -y
µÇ¼ºó¸´ÖÆ
Æô¶¯xrdpЧÀÍ
×°ÖÃÍê³Éºó£¬ÎÒÃÇÐèÒªÆô¶¯xrdpЧÀÍ¡£ÔÚÖÕ¶ËÖÐÖ´ÐÐÒÔÏÂÏÂÁ
sudo systemctl start xrdp
µÇ¼ºó¸´ÖÆ
ÉèÖÃxrdpЧÀÍΪ¿ª»ú×ÔÆô¶¯
ΪÁËÈ·±£xrdpЧÀÍÔÚЧÀÍÖØÊÓÆôºó×Ô¶¯Æô¶¯£¬ÎÒÃÇÐèÒª½«ÆäÉèÖÃΪ¿ª»ú×ÔÆô¶¯¡£Ö´ÐÐÒÔÏÂÏÂÁ
sudo systemctl enable xrdp
µÇ¼ºó¸´ÖÆ
µ÷½â·À»ðǽÉèÖÃ
ĬÈÏÇéÐÎÏ£¬CentOSЧÀÍÆ÷ÉϵķÀ»ðǽ¿ÉÄÜ»á×èÖ¹RDPÅþÁ¬¡£ÎÒÃÇÐèÒªÉèÖ÷À»ðǽÒÔÔÊÐíRDPÅþÁ¬¡£Ö´ÐÐÒÔÏÂÏÂÁ
sudo firewall-cmd --permanent --add-port=3389/tcp sudo firewall-cmd --reload
µÇ¼ºó¸´ÖÆ
½¨ÉèÒ»¸öеÄÓÃÓÚRDPµÇ¼µÄÓû§
ΪÁËÔöÌíÇå¾²ÐÔ£¬ÎÒÃÇ¿ÉÒÔ½¨ÉèÒ»¸öеÄÓû§×¨ÃÅÓÃÓÚRDPµÇ¼¡£Ö´ÐÐÒÔÏÂÏÂÁÉèÒ»¸öÃûΪrdpuserµÄÐÂÓû§£¨¿ÉÒÔÌ滻ΪÄú×Ô¼ºµÄÓû§Ãû£©£º
sudo adduser rdpuser sudo passwd rdpuser
µÇ¼ºó¸´ÖÆ
ÊÚÓèÓû§RDP»á¼ûȨÏÞ
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª½«ÐÂÓû§Ìí¼Óµ½Ò»¸öÃûΪ”tsusers”µÄÌØÊâ×éÖУ¬ÒÔÊÚÓèËü¶ÔxrdpµÄ»á¼ûȨÏÞ¡£Ö´ÐÐÒÔÏÂÏÂÁ
sudo usermod -aG tsusers rdpuser
µÇ¼ºó¸´ÖÆ
ÉèÖÃRDPµÇ¼»á»°
·¿ªÎļþ”/etc/xrdp/xrdp.ini”¾ÙÐÐÉèÖá£ÕÒµ½ÒÔÏÂÐв¢½«Æä×¢Ê͵ô£º
# security_layer = auto
µÇ¼ºó¸´ÖÆ
Ìí¼ÓÒÔÏÂÁ½ÐÐÀ´ÆôÓüÓÃܹ¦Ð§£º
security_layer = tls crypto_policy = layers
µÇ¼ºó¸´ÖÆ
ÖØÆôxrdpЧÀÍ
Íê³ÉÉÏÊöÉèÖúó£¬ÎÒÃÇÐèÒªÖØÐÂÆô¶¯xrdpЧÀÍÒÔʹÆäÉúЧ¡£Ö´ÐÐÒÔÏÂÏÂÁ
sudo systemctl restart xrdp
µÇ¼ºó¸´ÖÆ
ÏÖÔÚ£¬ÎÒÃÇÒѾÀֳɵØÉèÖÃÁËCentOSЧÀÍÆ÷ÒÔÖ§³ÖÇå¾²µÄRDPÅþÁ¬¡£Äú¿ÉÒÔʹÓÃÈκαê×¼µÄRDP¿Í»§¶ËÅþÁ¬µ½Ð§ÀÍÆ÷µÄIPµØµã£¬Í¨¹ýÖ¸¶¨Óû§ÃûºÍÃÜÂë¾ÙÐеǼ¡£
Çë×¢ÖØ£¬ÎªÁËÔöÇ¿Çå¾²ÐÔ£¬½¨ÒéʹÓÃÖ¤Êé»òÃÜÔ¿À´¾ÙÐÐÉí·ÝÑéÖ¤¡£ÈôÊÇÄúÏë½øÒ»²½ÔöÇ¿Çå¾²ÐÔ£¬¿ÉÒԲο¼Ïà¹ØÎĵµÏàʶÔõÑùÉèÖÃSSLÖ¤Êé¡£
×ܽ᣺
±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃÇå¾²µÄRDPÐÒéÀ´»á¼ûCentOSЧÀÍÆ÷¡£ÎÒÃÇͨ¹ý×°ÖÃxrdpЧÀͲ¢¾ÙÐÐÏìÓ¦µÄÉèÖã¬Ê¹µÃCentOSЧÀÍÆ÷Ö§³ÖRDPÐÒé¡£±ðµÄ£¬ÎÒÃÇ»¹ÏÈÈÝÁËÔõÑù½¨ÉèÒ»¸öеÄÓû§²¢ÊÚÓèÆäRDP»á¼ûȨÏÞ¡£Í¨¹ýÕâЩ°ì·¨£¬ÎÒÃÇ¿ÉÒÔʵÏÖ¶ÔCentOSЧÀÍÆ÷µÄÇå¾²Ô¶³Ì»á¼û¡£
²Î¿¼´úÂ룺
import paramiko def rdp_login(ip, username, password): # ½¨ÉèSSH¿Í»§¶Ë client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: # ÅþÁ¬Ð§ÀÍÆ÷ client.connect(ip, username=username, password=password) print("RDPµÇ¼Àֳɣ¡") except paramiko.AuthenticationException: print("RDPµÇ¼ʧ°Ü£ºÓû§Ãû»òÃÜÂë¹ýʧ¡£") except paramiko.SSHException as e: print("RDPµÇ¼ʧ°Ü£º" + str(e)) except paramiko.ssh_exception.NoValidConnectionsError as e: print("RDPµÇ¼ʧ°Ü£º" + str(e)) finally: # ¹Ø±ÕÅþÁ¬ client.close() # ʾÀý£ºÊ¹ÓÃRDPµÇ¼µ½CentOSЧÀÍÆ÷ rdp_login("192.168.0.100", "rdpuser", "password")
µÇ¼ºó¸´ÖÆ
ΪÁËʹÓÃÉÏÊö´úÂ룬ÄúÐèҪװÖÃPythonµÄparamiko¿â¡£Äú¿ÉÒÔͨ¹ýÖ´ÐÐÒÔÏÂÏÂÁîÀ´×°ÖÃËü£º
pip install paramiko
µÇ¼ºó¸´ÖÆ
Çë×¢ÖØ£¬Ê¾Àý´úÂë½öÓÃÓÚÑÝʾÔõÑùʹÓÃparamiko¿â¾ÙÐÐRDPµÇ¼¡£ÏÖÕæÏàÐÎÖУ¬ÎÒÃǽ¨ÒéʹÓøüÇ¿Ê¢µÄ¹¤¾ßÈçPyWinRM»òAnsibleÀ´¾ÙÐÐÔ¶³ÌЧÀÍÆ÷ÖÎÀí¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃÇå¾²µÄÔ¶³Ì×ÀÃæÐÒ飨RDP£©À´»á¼ûCentOSЧÀÍÆ÷µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡