Use the Public/private key to allow Putty (SSH) to log in automatically (and use the key for SSH automatic login on Linux) __linux

Source: Internet
Author: User
Tags chmod
Method One: Use Puttygen.exe

The first step: Creating a secret
key

Run Puttygen.exe, select the key type and length you want, use the default SSH2 (RSA), and set the length to 1024.
Passphrase can be empty so that you don't have to enter a password at logon.

Click the Save private Key button to save the public key and private key, for example, Key.ppk,public key does not need to be saved, then the Puttygen.exe load feature can be used to display the common key.

Step Two: Upload the key
Log on to the Linux host with your account, and then execute the following command:
$ cd ~
$ mkdir. SSH
$ chmod. SSH
$ CD. SSH
$ cat > Authorized_keys
(Copy the contents of the Puttygen public Key text box and press CTRL + C to copy to the Clipboard.) Previously generated key, then use the Load function, you can display the public key, and then in the Putty window press Shift+ins paste)
(Press the Ctrl+d key again to finish creating the file)
$ chmod Authorized_keys

Step three: Set up putty
1) Start putty, set the parameters of the session ( If you've already set it before, load it., then select "Ssh->auth" from the left and click the Browse button to select the Key.ppk file.
2) Set Auto-login username, Connection-> Data-> auto-login username
3) Then select the session from the left and click the Save button to save the changes。 Then click the Open button to sign in.
If the above operation is not a problem, then should be automatically logged in, do not need to enter a password.

Here basically can end ....
But if you want this private key to be used on a Linux host, do not use the password to land on a host with public key,
So:

Fourth step: Linux private Key Settings
(Run Puttygen.exe,load Save the KEY.PPK, if not closed Puttygen.exe,
This step is not necessary.
Select Menu Conversions->export OpenSSH key, save as file Id_rsa, upload to Linux
Host ~/.ssh/directory, so this host can not use the password to log in front of the public key
On the mainframe.
$ chmod ~/.ssh/id_rsa

=================================================

method Two: Use Linux command Ssh-keygen
first step: Generate Key
Ssh-keygen-b key Length-t key type
The key types can be: RSA1 (corresponding to SSH1 RSA), RSA, and DSA (corresponding SSH2)
Such as:
$ ssh-keygen-b 1024-t RSA
Id_rsa and id_rsa.pub are generated by default under ~/.ssh
Here Id_rsa is private key,id_rsa.pub is public key (key type RSA, key length 1024).

Step two: Set up the Linux host
Copy the id_rsa.pub to Authorized_keys
.
, placed in the ~/.SSH directory of the Linux host that needs to be landed

$ SCP id_ras.pub Hostname1:/home/username/.ssh/authorized_keys

This can be used without the password ssh to hostname1 (hostname1 and username according to their own situation, username and local same, different words to explicitly specify user name: SCP id_ras.pub username@hostname1:/ Home/username/.ssh/authorized_keys)

If you want to use putty, because the Ssh-keygen generated SSH2 key and Putty key format is different, can not be used directly,
Must be converted with Puttygen.exe:

Step three: Convert private key, set putty
Use WINSCP (recommended) or Psftp.exe or FTP to download Id_rsa to local, run Puttygen.exe, select Menu Conversions->import key
Then save private key (such as KEY.PPK), you can use this private key to set the putty, and set the same method as above.

Note: The red file name above is fixed and do not use a different filename.

Putty.exe and Puttygen.exe Download address:
Http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

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.