When learning big data, I need to configure a clustered distributed environment, including four servers from HadoOP100 to Hadoop103. To facilitate management, I need to log in to the four servers from the local terminal (Mac OS), so I have configured SSH pass-through login

1. SSH password-free login principle

2. Procedure

Now assume that host A wants to use SSH to log in to host B without password

# Install openssh-server/Openssh-client on both machines
$ sudo apt install openssh-server
$ sudo apt install openssh-client

# Check whether the SSH service is enabled
$ netstat -tlp | grep ssh 

Generate the key pair using RSA algorithm on host A
$ ssh-keygen -t rsa SSH file id_rsa (private key) and id_rsa.pub(public key)

# upload public key to host B's ~/.ssh/authorized_keys
$ ssh-copy-id username@hostB

# (Optional below)
Configure the server alias file
$ vim ~/.ssh/config
Copy the code

The contents of the ~/. SSH /config file are as follows

  • Host: server alias
  • HostName: server IP address (obtained by VMware NAT in this project)/host name/domain name/etc/hostsWrite the mapping between IP and domain name in the file.
  • User: indicates the User name
  • Port: indicates the SSH Port number
  • IdentityFile: private key file of host A (in this case, the local Macbook)

After the configuration is complete, enter the information on host A’s terminal

$SSH server alias$SSH username@hostB if config file is not configured
Copy the code

Warning: setlocale: LC_CTYPE: cannot change locale option (UTF-8) (warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory)

To solve this problem, add the following code to /etc/environment and log in to the system using SSH again

LC_ALL=zh_CN.UTF_8
LANG=zh_CN.UTF_8
Copy the code

3. Function of files in ~ /. SSH /

Id_rsa (private key)

The private key generated using the RSA algorithm is a pair of the generated public key. Connects to other servers

Id_rsa. Pub (Public key)

The public key generated using the RSA algorithm is a pair of the generated private key. Connects to other servers

Authorized_keys authorized_keys

If the public key of host A is in the authorized_keys file of host A, host A can log in to the local server without encryption

known_hosts

The public key of the host accessed by the local host is recorded. The next time the host is accessed, OpenSSH checks the public key and sends a warning to prevent attacks such as DNS Hijack

Config (Configuration file)

Not required, there is no config file to start with. It records some SSH configuration information (host alias/host name or IP address/username /SSH port /IdentityFile). If the config file is not configured, you need to run the SSH username@hostB command to connect to other hosts using SSH. After the configuration, you can directly SSH host

The resources

Function of files in the. SSH directory in Linux