Linux remote logon and password-less logon

Source: Internet
Author: User
This article mainly introduces the Linux remote logon and password-less logon methods, as well as some remote logon FAQs and sshd_config Chinese annotations. For more information, see

I. remote logon method

SSH is a secure channel protocol used for remote logon. In RHEL 5 systems, the OpenSSH server is provided by software packages such as openssh and openssh-server (installed by default) and added as a standard system service. The usage is as follows:

Copy codeThe code is as follows:
$ Ssh host
$ Ssh-p 222
-P: specifies the access port. If this parameter is omitted, the default access port 22 of the SSH service is used by default;
If you log on to the host for the first time, the system displays the following prompt:

Copy codeThe code is as follows:
The authenticity of host 'host (192.168.0.21) 'can't be established.
RSA key fingerprint is 98: 2e: d7: e0: de: 9f: ac: 67: 28: c2: 42: 2d: 37: 16: 58: 4d.
Are you sure you want to continue connecting (yes/no )?

In this section, you cannot confirm the authenticity of the host. you only know its public key fingerprint. do you want to continue the connection?
After you enter yes, a message is displayed, indicating that the host has been recognized.

Copy codeThe code is as follows: Warning: Permanently added 'host, 192.168.0.21 '(RSA) to the list of known hosts.

Then, enter the password:

Copy codeThe code is as follows:
$ Password: (enter password)
In this case, if the secret is correct, you can log on.

2. logon without a password

In a trusted environment, it is a waste of time to enter a password every time you log on remotely, especially when the password is complex and the number of servers maintained is large.
As a result, you can log on remotely without entering a password.
The implementation steps are as follows:

1. generate a local key File (public key and private key );

Copy codeThe code is as follows:
$ Ssh-keygen
# The preceding command is equivalent to ssh-keygen-t rsa.
#-T: specifies the key type, which is the rsa type of the SSH-2 by default;

After running the above command, the system will display a series of prompts, you can press enter all the way. Note: One problem is whether to set a passphrase password for the private key. if you are worried about the security of the private key, you can set one. After running ~ Two new files are generated under the/. ssh/directory: id_rsa.pub and id_rsa. The former public key, and the latter is the private key.
2. send the public key to the remote host;

Copy codeThe code is as follows: $ ssh-copy-id

After the above two steps, you can achieve remote login without a password (the remote host saves the user's public key in ~ /. Ssh/authorized_keys file ).

III. FAQs:

1. after the key is generated and uploaded to the remote host, it still cannot be logged on without a password?
Open the/etc/ssh/sshd_config file of the remote host and uncomment the following lines.

Copy codeThe code is as follows:
# RSAAuthentication = yes
# PubkeyAuthentication = yes
# AuthorizedKeysFile =. ssh/authorized_keys

Then, restart the ssh service of the remote host.

Copy codeThe code is as follows:
# Ubuntu system
$ Service ssh restart
# Debian system
$/Etc/init. d/ssh restart

2. when executing the ssh-copy-id command, the SSH service port of the remote server is not 22, as shown below:

Copy codeThe code is as follows: $ ssh-copy-id ssh: connect to host machineB port 22: Connection refused

Run the following command:

Copy codeThe code is as follows:
$ Ssh-copy-id "-p 22000
IV. supplementary content:

Copy codeThe code is as follows:
$ Ssh-copy-id-I ~ /. Ssh/id_rsa.pub $ ssh-copy-id-u eucalyptus-I/home/eucalyptus/. ssh/id_rsa.pub #-u: set logon without password for eucalyptus users
#-I: When no value is transferred or ~ The/. ssh/identity. pub file is inaccessible (does not exist), and the following error is displayed for ssh-copy-id:
/Usr/bin/ssh-copy-id: ERROR: No identities found

SSH provides two logon verification methods:
1. Password verification: Use the login name and password of the local system user on the server for verification.
2. verify the key pair: you must provide the matching key information to pass the verification. Generally, create a pair of key files (public and private keys) in the client, and then place the public key files in the specified location on the server.
Note: When both password verification and private key verification are enabled, the server will give priority to key verification.

5. SSH service configuration file:

By default, the configuration file of the sshd service is in/etc/ssh/sshd_config. correct configuration items can further improve the security of sshd remote logon.

The configuration file content can be divided into the following three parts:

Copy codeThe code is as follows:
# SSH server listening options
# Listening port
Port 22
# Using the SSH V2 protocol
Protocol 2
# The Listening address is all addresses.
ListenAdderss 0.0.0.0
# // Disable reverse DNS resolution
UseDNS no

# User logon control options
# Allow root users to log on
PermitRootLogin no
# Whether to allow logon with a blank password
PermitEmptyPasswords no
# Logon verification time (2 minutes)
LoginGraceTime 2 m
# Maximum number of retries
MaxAuthTries 6
# Allow Only user users to log on, opposite to the DenyUsers option
AllowUsers user

# Logon authentication method
# Enable Password verification
PasswordAuthentication yes
# Enable key verification
PubkeyAuthentication yes
# Specify the public key database file
AuthorsizedKeysFile. ssh/authorized_keys

Command:/etc/init. d/sshd status
Restart the SSH service command:/etc/init. d/sshd restart
Run the command $ ssh-V to view the version number of the ssh software.
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003 # indicates that the system is using OpenSSH
Ssh: SSH Secure Shell 3.2.9.1 (non-essential cial version) on i686-pc-linux-gnu # indicates that the system is using SSH2
When the public key of the remote host is accepted, it will be saved in the file $ HOME/. ssh/known_hosts. Next time you connect to the host, the system will recognize that its public key has been saved locally, skip the warning section and prompt you to enter the password.
Each SSH user has its own known_hosts file, and the system also has such a file, usually/etc/ssh/ssh_known_hosts, save the public keys of remote hosts trusted to all users.

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.