Linux SSH Remote Management

An openSSH server

1. Introduction to ssh protocol

	ssh Protocol is a secure channel protocol, which encrypts the communication data for remote management

2,openSSH

Service Name: sshd
 Server main program:/usr/sbin/sshd
 Server configuration file:/etc/ssh/sshd_config

2, Configure OpenSSH server

1,sshd_ Common options for config configuration files

Configuration itemeffect
vim /etc/ssh/sshd_configEnter configuration file
Port 22The listening port is 22
ListenAddress 0.0.0.0The listening address is any network segment. You can also specify the specific IP of the OpenSSH server
LonginGreaceTime 2mThe login verification time is 2 minutes
PermitRootLogin noDisable root login
MaxAuthTries 6max retries
PermitEmptypasswords noProhibit users with blank passwords from logging in
UseDNS noDisable DNS reverse resolution to improve the response speed of the server
AllowUsers userOnly one user is allowed to log in, multiple users are separated by spaces, and the white list effect
DenyUsers userOnly some users are forbidden to log in, and multiple users are separated by spaces. The blacklist effect

Column: AllowUsers lisi@192.168.66.66 Only Lisi users are allowed to log in from 192.168.66.66 IP
AllowUsers and DenyUsers cannot be used at the same time

3, The sshd service supports two authentication methods

1. Password verification

	It is easy to verify the login name and password of the local system user in the server, but it may be brutally cracked.

2. ssh client program

① . ssh [options] user @ IP address

		-P: Specifies the default port number. By default, port 22 is used
		ssh -p 66 luoxiang@192.168.66.66	To user luoxiang Port 66 login

② scp, remote replication

optionexplain
-1Force ssh protocol version 1
-2Force ssh protocol version 2
-4Force IPv4 address
-6Force IPv6 address
-ATurn on the authentication agent connection forwarding function
-aTurn off the authentication agent connection forwarding function
-bUse the address specified by the machine as the source IP address of the peer-to-peer connection
-CRequest to compress all data
-FSpecify the SSH instruction configuration file. The default configuration file is "/ etc/ssh/ssh_config"
-fExecute ssh instruction in the background
-gAllow remote hosts to connect to local forwarding ports
-iSpecify identity file (i.e. private key file)
-lSpecify the login user name to connect to the remote server
-NDo not execute remote instructions
-oSpecify configuration options
-pSpecify the port on the remote server
-qIn silent mode, all warning and diagnostic information is prohibited from being output

(1) Downlink replication

	scp	 user@ip address:Directory to copy target files  /Copy to local location directory
 Columns: scp luoxiang@192.168.66.66:/etc/passwd  /root/	The remote host/etc/passwd Copy to local/root catalogue

(2) Uplink replication

	scp  /etc/passwd/  	luoxiang@192.168.66.66:/root/
	Connect the local /etc/passwd Copy to remote host root Directory

Non administrator users should pay attention to whether they have corresponding permissions.

4. sftp Secure FTP

Encryption is used/Decryption technology, so the transmission efficiency is higher than ordinary FTP Lower, but more secure
sftp user@IP address
 Enter user password
sftp>ls  Look at the files
sftp>get file name		Download the file to the directory at the time of current login
sftp>put file name		Upload files to the directory at the time of current login
sftp>quit			sign out
***Copy directory plus -r ****** For example: get -r  free 
***The default is the current login directory. You can add a specific directory later,as get -r mmp  /opt copy mmp Directory to opt Directory. 

3. Secret key verification

①It is required to provide matching secret key information to pass the verification. Generally, a pair of secret key files (public key and private key) are created in the client, and then the public key file is placed in the specified location in the server. During remote login, the system will decrypt with the public key and private key/Encrypted Association verification, secure and interaction free

②When both password authentication and secret key authentication are enabled, the server will give priority to secret key authentication,
vim /etc/ssh/sshd_config		Enter configuration file
Configuration itemtask
PasswordAuthentication yesEnable password authentication
PubkeyAuthentication yesEnable secret key authentication
AuthorizedKeyFile .ssh/authorized_keysSpecify public key library file

1. Make secret key pair

1. Establish key pair

[root@host ~]$ ssh-keygen  <== Establish key pair
		Generating public/private rsa key pair.
		Enter file in which to save the key (/root/.ssh/id_rsa): <== Press Enter
		Created directory '/root/.ssh'.
	Enter passphrase (empty for no passphrase): <== Enter the key lock code, or press directly 	Enter leave a blank
	Enter same passphrase again: <== Enter the key lock code again

2. Upload public key to server

		scp ~/.ssh/id_ecdsa.pub  root@192.168.60.66:/opt

3. Import public key text in the server

4. Use secret key authentication on the client
**********************Log in with the user who created it********************

Keywords: Linux ssh

Added by Sindarin on Sun, 23 Jan 2022 22:04:30 +0200