Automatically log on to linux (ubuntu) using the putty program on windows using ssh)

Source: Internet
Author: User
Automatically log on to linux (ubuntu) using the putty program on windows using ssh)

Method 1: Use puttygen.exe

Step 1: generate a key
Run puttygen.exe, select the type and length of the key, and use the default SSH2 (RSA). Set the length to 1024.
Passphrase can be blank to avoid entering a password at login.

Click Save private key to Save the private key, for example, key. ppk;
Copy the content in the puttygen public Key text box to the clipboard.

Step 2: Upload the key
Use PuTTY 0.60 (Linux sshini.exe to connect to the linux machine, the account is chenxiaowen, and then execute the following command:
$ Cd ~ [Open the document directory of the Logon account, which is equivalent to the directory C: \ Users \ lenovo under windows]
$ Mkdir. ssh [create. ssh directory. if it already exists, do not create it. This directory is not visible on linux by default (check the menu in the file browser> show hidden files to see this folder )]
$ Chmod 700. ssh [Modify file permissions. "700" indicates the read, write, and execute permissions for the user (7 at the beginning), but does not grant permissions to the group or other users (the next two are 0 )]
$ Cd. ssh
$ Cat> authorized_keys [create a file named authorized_keys and input the following content to the file]
Paste the copied public key content (paste method: Press Shift + Ins or right-click in the Putty window );
Press Ctrl + D to save the input content of cat to the file (ctrl + c indicates that the input is not saved ).
[During the input process, press enter to immediately Save the text you just entered and add a header to 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 it, load it)
In the "SSH-> Auth" menu, click the Browse button and select the key. ppk file.
2) choose Connection> Data> Auto-login username and enter the name of the account used for automatic logon. The name is chenxiaowen, which corresponds to
3)Select Default Settings and click Save to Save the changes.. Click the Open button to log on.
If your operations are not problematic, you can directly run the program putty.exe without entering the password to automatically log on. The logon prompt is as follows:
---------------- Using username "chenxiaowen ". authenticating with public key "rsa-key-20100412" Linux chenxiaowen-laptop 2.6.31-14-generic # 48-Ubuntu SMP Fri Oct 16 14:04:26 UTC 2009 i686To access official Ubuntu documentation, please visit: http://help.ubuntu.com/260
Packages can be updated.106 updates are security updates. Last login: Mon Apr 12 22:15:24 2010 from 192.168.0.132chenxiaowen @ chenxiaowen-laptop :~ $ ----------------
-----------------------
It can basically end here ....
However, if you want to use this private key on a linux host, you do not need to use a password to log on to the host with the public key,
So:

Step 4: linux private key settings
(Run puttygen.exe, and load the key.ppk stored before. If puttygen.exe is not disabled,
This step is unnecessary)
Choose Conversions> Export OpenSSH key, save it as the file id_rsa, and upload it to linux
Host ~ /. Ssh/directory, so that this host can log on to the front with a public key without a password
Host.
$ Chmod 600 ~ /. Ssh/id_rsa

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

Method 2: Use the linux Command ssh-keygen
Step 1: generate a key

Ssh-keygen-B key length-t key type
Key types can be: rsa1 (corresponding to SSH1 RSA), rsa and dsa (corresponding to SSH2)
For example:
$ Ssh-keygen-B 1024-t rsa
The default value is ~ /. In ssh, id_rsa and id_rsa.pub are generated.
Here id_rsa is private key and id_rsa.pub is public key (key type RSA, key length 1024 ).

Step 2: Set the linux host
Copy id_rsa.pub to authorized_keys.
To be logged on to the linux host ~ /. Ssh directory

$ Scp id_ras.pub hostname1:/home/username/. ssh/authorized_keys

In this way, you do not need to ssh the password to hostname1 (hostname1 and username are based on your own situation. 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 of putty, you cannot directly use it,
Puttygen.exe must be used for conversion:

Step 3: Convert private key and set putty
Use winscp (recommended) or psftp.exe unzip ftpto download id_rsato the local directory, run puttygen.exe, and choose Conversions> Import
Key
Then save private key (such as key. ppk), you can use this private key to set putty. The setting method is the same as above.

Note: The above red file names are fixed. Do not use other file names.

Putty.exeand puttygen.exe:
Http://www.chiark.greenend.org.uk /~ Sgtatham/putty/download.html

Original article title: use the public/private key to allow putty (ssh) to log on automatically (and use the key for ssh automatic login on linux) _ Felix study note _ Baidu space I edited method 1, which should look clearer.

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.