Generate a key in linux

Source: Internet
Author: User
In linux, generate a key and use public/privatekey to allow putty (ssh) to log on automatically (and use the key for ssh automatic logon in linux). Method 1: Use puttygen.exe. Step 1: generate a secret to run puttygen.exe, select the type and length of the key, and use the default SSH2 (RSA )... in linux, the public/private key is generated to allow putty (ssh) to log on automatically (and ssh to log on automatically using the key in linux). Method 1: Use puttygen.exe. Step 1: generate a key to run puttygen.exe, select the desired key type and length. use the default SSH2 (RSA) and set the length to 1024. Passphrase can be blank to avoid entering a password at login. Click the Save private key button to Save the public key and private key, for example, key. ppk and public keykeys, and use puttygen.exe Load to display the public key. Step 2: upload the key and use your account to log on to the linux host. then run the following command: $ cd ~ $ Mkdir. ssh $ chmod 700. ssh $ cd. ssh $ cat> authorized_keys (copy the content in the puttygen public Key text box and press Ctrl + C to copy it to the clipboard. The previously generated key can be displayed using the load function, and then press Shift + Ins in the Putty window) (press Ctrl + D to create the file) $ chmod 600 authorized_keys Step 3: Set Putty 1) start Putty and set the parameters of the session (if you have already set them, load them ), select "SSH-> Auth" from the left, click the Browse button, and select key. ppk file. 2) set the auto-login username, Connection-> Data-> Auto-login username 3) Select Session from the left side, and then click Save to Save the modification. Click the Open button to log on. If there are no problems with the above operations, then the system should automatically log on without entering the password. It can basically end here .... However, if you want this private key to be used on a linux host and do not need a password to log on to the host with a public key, Step 4: Set the linux private key (run puttygen.exe, save the key.ppk before load. if puttygen.exe is not disabled, this step is unnecessary. select Conversions> Export OpenSSH key from the menu, save it as the file id_rsa, and upload it to the linux host ~ In the/. ssh/directory, this host can be logged on to the host with a public key in front of it without a password. $ Chmod 600 ~ /. Ssh/id_rsa ========================================== ============= Method 2: use the linux command ssh-keygen Step 1: generate key ssh-keygen-B key length-t key type can be: rsa1 (corresponding to SSH1 RSA), rsa and dsa (corresponding to SSH2) such as: $ ssh-keygen-B 1024-t rsa by default in ~ /. In ssh, id_rsa and id_rsa.pub are generated. here id_rsa is the private key and id_rsa.pub is the public key (key type RSA, key length 1024 ). Step 2: Set the linux host to copy id_rsa.pub to authorized_keys and place it in ~ /. $ Scp id_ras.pub hostname1:/home/username /. ssh/authorized_keys so that you do not need to ssh the password to hostname1 (hostname1 and username are determined based on your own situation, and the user name is the same as the local one. Otherwise, you must explicitly specify the user name: scp id_ras.pub username @ hostname1:/home/username /. ssh/authorized_keys) if you want to use putty, because the format of the SSH2 key generated by ssh-keygen is different from that generated by putty, you cannot directly use it. you must use puttygen.exe to convert it: Step 3: convert private key, set putty to use winscp (recommended) or psftp.exe unzip ftpto to download id_rsato external, run puttygen.exe, select the menu Conversions-> Im Port key and save private key (such as key. ppk). you can use this private key to set putty. the setting method is the same as above.
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.