Python for password-free login to Lunx server

Source: Internet
Author: User

Import Paramiko
Import OS
Hostname= ' 192.168.76.10 '
Username= ' Root '
# password= ' 123456 '
Ssh=paramiko. Sshclient ()
Ssh.load_system_host_keys ()
# Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy)
Privatekey=os.path.expanduser (' d:/job/id_rsa_2048 ')
Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy)
Key=paramiko. Rsakey.from_private_key_file (Privatekey)
Ssh.connect (Hostname=hostname,username=username,pkey=key)
Stdin,stdout,stderr=ssh.exec_command (' free-m ')
Print Stdout.read ()
Ssh.close ()

    • The use of the principle of public key, such as a PC and a server, the PC would like to implement password-free login to the Linux server, you can generate a public key and key, copy the public key to the LUNX server, log in with their own key to log in
    1. Where Xshell can implement the PC's public key and key: Tools-New User Password Wizard to create a public key
    2. On the server side ssh-keygen-t RSA can create the. ssh directory under the root directory and modify the permissions, so we use this tool to generate directly, so as not to create directories and modify the password, in the. SSH directory under the Id_rsa and id_rs_pub separate private key and public key, is used to log in to others without a password
    3. Create the Authorized_keys file in the. ssh directory and copy the public key content generated by the PC.
    4. Configured to use the private key verification can be password-free login.

Python for password-free login to Lunx server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.