How to pass echo y to plink.exe for first connection

巧了我就是萌 提交于 2019-11-27 07:30:15

问题


I would like to pass echo y to plink.exe, so that plink execute a command. How it can be achieved?

os.system(' c:/netapp/python/plink.exe admin@192.168.1.1 -pw xxx  uptime > c:/netapp/python/12.txt')

The server's host key is not cached in the registry. You have no guarantee that the server is the computer you think it is. The server's rsa2 key fingerprint is: ssh-rsa 2048 9d:08:37:a8:d0:34:a3:d2:d8:e5:09:7e:63:08:a9:1b If you trust this host, enter "y" to add the key to

Store key in cache? (y/n)


回答1:


Do not!

Verifying host key fingerprint is an integral part of securing your connection. Blindly accepting any host key will make you vulnerable to the man-in-the-middle attacks.


Instead, use the -hostkey switch to provide the fingerprint of the expected/known host key.

c:/netapp/python/plink.exe admin@192.168.1.1 -pw xxx -hostkey 9d:08:37:a8:d0:34:a3:d2:d8:e5:09:7e:63:08:a9:1b uptime 

Do not use hacks like feeding y to Plink input. Not only it is insecure. But if there is no host key prompt (because the host key is already cached), the y will end up as an input to the command you are executing. What may lead to undesired results.




回答2:


Confirming a server's SSH key fingerprint is an important step. This is how you know you've connected to the correct machine, and should always be done with care.

The Plink documentation makes the following suggestion:

To avoid being prompted for the server host key when using Plink for an automated connection, you should first make a manual connection (using either of PuTTY or Plink) to the same server, verify the host key (see section 2.2 for more information), and select Yes to add the host key to the Registry. After that, Plink commands connecting to that server should not give a host key prompt unless the host key changes.



来源:https://stackoverflow.com/questions/38552236/how-to-pass-echo-y-to-plink-exe-for-first-connection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!