Linux ssh Configuration

Source: Internet
Author: User

Machine A does not need to enter A password to log on to machine B through ssh. When there are many servers in the application, it is A waste of time to enter A password. During Hadoop installation, password-free login is required;

1. Create a. ssh folder in the user's home directory

Mkdir. ssh

You can hide folders or file content.

Ls-

Ii. Generate a certificate

Certificates are classified into dsa and rsa.

Ssh-keygen-t rsa-p'-B 1024

Ssh-keygen Generation Command

-T indicates the rsa certificate.

-P password prompt''

-Certificate B: 1024

The key file and private key file will be generated after execution.

Ll

-Rwx ------ 1 apch apache 883 May 20 id_rsa
-Rwx ------ 1 apch apache 224 May 20 id_rsa.pub

3. Write the public key information to the authorized_keys document.

Cat id_rsa.pub> authorized_keys

(Write the generated public key file to the authorized_keys file)

Iv. Set file and directory permissions

Set authorized_keys Permissions
$ Chmod 600 authorized_keys
Set. ssh Directory Permissions
$ Chmod 700-R. ssh

5. Modify/etc/ssh/sshd_config (use the root user to log on)

Vi/etc/ssh/sshd_config

Protocol 2 (SSH2 only)
PermitRootLogin yes (allow root users to log on via SSH, according to The Logon account settings)

ServerKeyBits 1024 (change the serverkey strength to 1024)

PasswordAuthentication no (password login is not allowed)

PermitEmptyPasswords no (do not log on with a blank password)

RSAAuthentication yes (RSA Authentication enabled)

PubkeyAuthentication yes (enable public key authentication)

AuthorizedKeysFile. ssh/authorized_keys

6. Restart the sshd service (use the root user to log on)

Service sshd restart

VII. Local verification test

Ssh-v localhost (enable logon debugging mode)

If the password is entered, the operation is unsuccessful.

Debug1: Authentications that can continue: publickey, password
Debug1: Next authentication method: publickey
Debug1: Trying private key:/home/hadoop/. ssh/identity
Debug1: Offering public key:/home/hadoop/. ssh/id_rsa
Debug1: Server accepts key: pkalg ssh-rsa blen 149
Debug1: read PEM private key done: type RSA
Debug1: Authentications that can continue: publickey, password
Debug1: Offering public key:/home/hadoop/. ssh/id_dsa
Debug1: Authentications that can continue: publickey, password
Debug1: Next authentication method: password
Hadoop @ localhost's password:

View error logs

Log On with the root user to view the System Log File

Tail-50f/var/log/secure

May 20 16:35:37 JTMCRM195 sshd [7838]: Authentication refused: bad ownership or modes for directory/home/hadoop
May 20 16:35:37 JTMCRM195 sshd [7838]: Authentication refused: bad ownership or modes for directory/home/hadoop
May 20 16:36:05 JTMCRM195 sshd [7839]: Connection closed by 127.0.0.1
May 20 16:36:12 JTMCRM195 sshd [7848]: Authentication refused: bad ownership or modes for directory/home/hadoop
May 20 16:36:12 JTMCRM195 sshd [7848]: Authentication refused: bad ownership or modes for directory/home/hadoop

The. ssh directory permission should be incorrect from the log. Please perform Step 4 again;

8. Copy id_rsa and id_rsa.pub to other application servers:

Scp id_rsa hadoop @ IP:/home/hadoop/. ssh

Remote replication

Scp id_rsa.pub hadoop @ IP:/home/hadoop/. ssh

Remote replication

Log on to the Application Server (IP address), and then perform step 3 to Step 7;

 

9. Verify Remote Password-free Logon:

Ssh 10.196.425194 (remote IP)

Summary:

1. Do not set the permissions of files and directories to chmod 777, so that the permissions are too large and there are security problems;

2. The generated rsa/dsa Signature public key is used by the other machine.

3. Access the ip address of the ssh machine directly between linux

4. configuration error: the permission or/etc/ssh/sshd_config settings are incorrect.

 

 

 

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.