当前位置:网站首页>Remote login sshd service
Remote login sshd service
2022-06-28 11:42:00 【redhat-YAN】
Remote login sshd service
One 、sshd The service is introduced
Openssh function
1.sshd Functions of services :
Security can be enabled on the remote host through the network shell operation
Secure SHell ssh client
Secure SHell daemon( Daemon , management ssh The process of , similar systemctld System daemons ) sshd Server side
2. Installation package
openssh-server
3. Master profile
/etc/ssh/sshd_conf
4. Default port 22( You can understand ,ip It's the gate of home , The port is the room door )
( The service is ip The open interface on the , To connect this interface is to use the functions of this program )
5. Client commands ssh
6. Experimental environment : Two virtual machines ,a Is the server ,b The client side.
Able to communicate , Close the drawing ,init 3
Two 、 Usage method
2.1 Basic usage
ssh It's used by the client , The server is connected
Can be in ssh Directly followed by the command
ssh -l Remote host users ( The server ) ip|hostname
ssh -l root 172.25.254.100
yes, The first connection will have 
fingerprint In your current directory .ssh/ Under
such as :cd /root/.ssh/
This file and the server 100 The above file is a match
Two key equally 

The second connection has no authentication fingerprint 
2.2 Analog matching ( authentication ) You don't succeed , Remote login failed
Delete the original key Restart the service , Then regenerate key
current key It's different from before 
Certification has changed , Authentication mismatch , Not through 
resolvent ( Prompt the red box to mark , There is a problem with this line of file ):
Delete the first line
summary :
When the connection is rejected due to authentication problems, the solution
Delete the corresponding line in the reminded file
3、 ... and 、 Common parameters
3.1 Common parameters
-l Specify the login user
-i Specify private key
-X Open graphics
-f Background operation
-o Specify connection parameters
-t Specify the connecting strip
3.2 Common parameter usage
-X Parameters
-X Open graphics
Real connection a host
ssh -l root 172.25.254.100
gedit Open graphics , It won't work
because ,ssh The default connection is text connection , Unable to open the graph
``
ssh -X -l root 172.25.254.100
gedit
With the right to open graphics software 
-f Parameters
Can be in ssh Directly followed by the command 
Waiting for the opening time will occupy your terminal
After entering the backstage , You can run new instructions at the terminal 
-o Parameters
Specify connection parameters , This parameter can be in man View in
The most common parameters StrictHostKeyChecking=no
ssh -o "StrictHostKeyChecking=no" -l root 172.25.254.100
It will be automatically input as yes

-t Parameters
Connect A Server time , I have no right , Another server 250 I can connect and another server can connect A The server , You can connect first 250 In by 250 Jump to the A
First connect to 250 The server is then controlled by 250 The server jumps to 100
This is the time A What the server sees is 250 The server connects to it 
Four 、key authentication
4.1 Concept
B The client side. ,A Is the server
ssh -l root 172.25.254.100 So the connection must know root The password of the user on the remote server

This authentication method is called user authentication
The authentication method is symmetric encryption , Encryption and decryption use the same string of characters , Such as : The fingerprint
Asymmetric encryption , Encryption and decryption are different , Keys and locks
Symmetric encryption , Easy to crack , Can be brutally cracked ( Try one by one with a fast computer ), So the password should have strength verification , also Easy to forget
Asymmetric encryption , Encryption uses the public key , Decryption with private key , Will not be stolen , An attacker cannot log on to the server without a secret key
4.2 Generate public key and secret key
Public and private keys do not have to be generated on the server side , Both client and server can generate public and private keys ( For example, you can buy locks )
For example, generate public and private keys on the client side
ssh-keygen Commands for generating public and private keys
Ask you key( The secret key encrypts the string file ) Where to keep it , If you change the save path, you need to change ssh Master profile , Change trouble , So just use the default 
Set a password , You need a secret key and a password ,( The password of the secret key ) trouble , Directly enter
The public and private keys generate 
cat /root/.ssh/id_rsa
This is the private key ( Unlock )
Public key ( locked )cat /root/.ssh/id_rsa.pub
From the server frigerprint Fingerprint authentication password , Prove that this host B Connect to server A It was the original host B
Both the generated public key and secret key are interactive , Not conducive to automatic operation
If you use scripts to generate public and secret keys , Scripts cannot run automatically
Automation is not interactive
ssh-keygen --help

Non interactive generation of public and secret keys -f Specify to save the encrypted file -P Indicates the specified password
ssh-keygen -f /root/.ssh/id_rsa -P ""

4.3 Use of public and private keys ( locked )
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
Password of the server to be locked , Ask the locked server for permission , Otherwise it is illegal
You can't lock someone's house with a lock 
This time the server A There will be multiple files , This file is actually a public key 
and B The public key of is the same
client B There's a private key , There is only one secret key 
Direct connection , No password required ( The only private key is used to open the public key by default )

If there are many private keys ,-i Specify the specific private key to open the public key 
4.4 summary
ssh-keygen -f /root/.ssh/id_rsa -P "" Generate Key
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected] use key Encrypt the server
After encrypting the server, there are two authentication methods , If you have a private key, you do not need to enter a password to connect , No private key input password connection
5、 ... and 、sshd Security optimization of services
5.1 Safety problem description
5.1.1 Original password and key authentication
7 Host can connect to our server A, Have the right to enter the password , But the function itself is not safe , It should not be opened , So turn off this function
So you need to run the server A Turn off unsafe functions on 
5.1.2 Modify the port
Do not modify port , As we all know, the port is 22 Default port
5.1.3 Limit who can connect and who can't
Set who can only be connected or who cannot be connected
5.2 Turn off the original password authentication
Edit server A Primary profile for 
Change to no The server A The password authentication function of is turned off , Only public and private keys (key) Authentication can be connected to
Before turning off password authentication , First, put key The authentication service is started , because Key Authentication requires password authentication to admit permission at the beginning Key authentication ( Allow locking )

Restart the service systemctl restart sshd
Now I have no right to enter the password , Now we can't even crack it by force , Because there is no way to enter the password 
5.3 Modify the port
Because the server is turned on selinux Will limit your port changes , You need to change selinux Warning mode
Close the fire wall 
systemctl disable --now firewalld
Because the fire wall only allows 22 port , If you open the fire wall 2021 The test failed
Modify master profile

Restart the service systemctl restart sshd
The port becomes 2021 了


5.4 Set connectable objects ( Black and white list of users )
White list Only on the list can they be ssh Connect
In the main configuration file , Find a space to write AllowUsers westos You can only connect to westos user
Restart the service systemctl restart sshd
Multiple users
AllowUsers westos root
Restart the service systemctl restart sshd
Successful connection 
The blacklist The list cannot be ssh Connect
DenyUsers westos
westos Cannot pass ssh Connect
Restart the service systemctl restart sshd
5.5 summary

边栏推荐
- This Exception was thrown from a job compiled with Burst, which has limited exception support. report errors
- MySQL installation configuration and solving the problem of forgetting root password when reinstalling MySQL
- 合约量化交易系统开发 | 合约量化APP开发(现成案例)
- Word、PDF、TXT文件实现全文内容检索需要用什么方法?
- 2022 open source software security status report: over 41% of enterprises do not have enough confidence in open source security
- mysql-.sql文件钓鱼上线
- This Exception was thrown from a job compiled with Burst, which has limited exception support. 报错
- Compareto() and equals() methods of BigDecimal class
- Join hands with cigent: group alliance introduces advanced network security protection features for SSD master firmware
- 2022 开源软件安全状况报告:超41%的企业对开源安全没有足够的信心
猜你喜欢

功能真花哨,价格真便宜!长安全新SUV真实力到底怎样?

Solve the problem of reading package listsdonebuilding dependency treereading state informationdone

《运营之光3.0》全新上市——跨越时代,自我颠覆的诚意之作!

Blue Bridge Cup Maze (dfs+ backtracking)

Redis6 1: what problems can be solved by the introduction of NoSQL and redis?

day31 js笔记 DOM下 2021.09.26

Day32 JS note event (Part 1) September 27, 2021

day34 js笔记 正则表达式 2021.09.29

Making and using of dynamic library (shared library)

Recommended practice sharing of Zhilian recruitment based on Nebula graph
随机推荐
分析list中有无重复数据且重复了几次
When an entity is converted to JSON, the field with null value is lost
Day24 JS notes 2021.09.15
使用API快捷创建ECS
Xshell和Xftp使用教程
It is safer for individuals to choose which securities company to open an account for buying floor funds
MySql5.7添加新用户
day37 js笔记 运动函数 2021.10.11
使用logrotate对宝塔的网站日志进行自动切割
毕业季 新的开始
选择哪种编程语言,会吸引优秀的人才?
行业分析| 快对讲,楼宇对讲
赛尔号抽奖模拟求期望
setInterval、setTimeout和requestAnimationFrame
ProCAST有限元铸造工艺模拟软件
Recommended practice sharing of Zhilian recruitment based on Nebula graph
Packaging and publishing application of jetpack compose desktop version
New listing of operation light 3.0 - a sincere work of self subversion across the times!
Docker modifies the user name and password of MySQL
携手Cigent:群联为SSD主控固件引入高级网络安全防护特性