This chapter is about the control of system services and the knowledge of how to communicate the host to the client via SSH.
# #系统服务的控制
Systemd
System initialization program, the first process that the system starts, the PID is 1
Systemctl command
Systemctl List-units # #列出当前系统服务的状态
Systemctl List-units-files # #列出服务的开机状态
Systemctl Status sshd # #查看指定服务的状态
Systemctl Stop sshd # #关闭指定服务
Systemctl Start sshd # #开启指定服务
systemctl Restart sshd # #重启指定 Service
Systemctl Enable SSHD # #设定指定服务开机启动
Systemctl Disable SSHD # #设定指定服务开机关闭
Systemctl Reload sshd # #使指定服务重新重新加载配置
Systemctl list-dependencies sshd # #查看指定服务的倚赖关系
Systemctl Mask sshd # #冻结指定服务
Systemctl unmask sshd # #解冻指定服务
Systemctl Set-default Multi-user.target # #开机不开启图形
Systemctl Set-default Graphical.target # #开机启动图形
Service status
Loaded # #系统服务已经完成初始化, loaded configuration
Active (running) # #服务正在被系统利用
Active (exited) # #服务已经加载过配置, waiting to be exploited by the system
Active (Waiting) # #服务等待被系统处理
Inactive # #服务关闭
Enable # #服务开机启动
Disable # #服务开机不自启
Static # #服务开机启动项不可被管理
Failed # #系统配置错误
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/88/95/wKioL1f8kFfD-gV8AALWJUzWTsk813.png-wh_500x0-wm_3 -wmp_4-s_466639242.png "title=" 1.png "alt=" Wkiol1f8kffd-gv8aalwjuzwtsk813.png-wh_50 "/>
# #ssh服务
1.openssh-server
Function: Allow remote host to access sshd service over the network, start a secure shell
2. Client Connection mode
SSH root/[email protected] accessed host IP
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M01/88/98/wKiom1f8khPhnTF0AAJAuk763gg231.png-wh_500x0-wm_3 -wmp_4-s_2035693179.png "title=" 2.png "alt=" Wkiom1f8khphntf0aajauk763gg231.png-wh_50 "/>
* When connecting unfamiliar hosts for the first time, you need to establish authentication
SSH root/[email protected] accessed host Ip-x # #调用远程主机图形工具
SSH root/[email protected] Accessed host IP command # #直接在远程主机运行某条命令
3.sshkey encryption
Sometimes we want to give some host privileges, so that they can not enter the password to connect our host, this time can be encrypted through Sshkey, make a "key" to transfer the "key" to the designated host, they connect our host, they can not enter the password
650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/88/95/wKioL1f8lAeRo-qMAARVvxieIAw028.png-wh_500x0-wm_3 -wmp_4-s_2394743064.png "title=" 3.png "alt=" Wkiol1f8laero-qmaarvvxieiaw028.png-wh_50 "/>
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/88/95/wKioL1f8lGiiKr4NAACi1wQnuv8909.png-wh_500x0-wm_3 -wmp_4-s_2535069239.png "title=" 4.png "alt=" Wkiol1f8lgiikr4naaci1wqnuv8909.png-wh_50 "/>
ls/root/.ssh/
We will see the following two files in the. ssh directory under the root directory.
Id_rsa # #私钥 is the key
Id_rsa.pub # #公钥 is the lock
2. Add key authentication method
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/88/98/wKiom1f8lXWD17y-AAIA0foaHjM322.png-wh_500x0-wm_3 -wmp_4-s_3797037298.png "title=" 5.png "alt=" Wkiom1f8lxwd17y-aaia0foahjm322.png-wh_50 "/>
3. Distribute key to client host
Scp/root/.ssh/id_rsa [email protected] User ip:/root/.ssh/
Through distribution, the keys are transferred to the client's mainframe, which is then tested.
4. Testing
650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/88/95/wKioL1f8lmGQeZEqAAE57vnrdJE799.png-wh_500x0-wm_3 -wmp_4-s_3374270095.png "title=" 6.png "alt=" Wkiol1f8lmgqezeqaae57vnrdje799.png-wh_50 "/>
5. Improve the OpenSSH security level
Openssh-sever configuration file:/etc/ssh/sshd_config
Line 48th: Permitrootlogin Yes|no # #是否允许超级用户登录
Line 49th: allowusers Kiosk LCDQQQ # #用户白名单, only users in the list can connect by using the SSHD service
Line 50th: denyusers Kiosk # #用户黑名单
Line 78th: passwordauthentication yes|no # #是否开启用户密码认证, yes on, no off, only the person holding the key after closing Can connect
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/88/99/wKiom1f8mJzAktkiAAHxr3omm5c043.png-wh_500x0-wm_3 -wmp_4-s_4193530918.png "title=" 7.png "alt=" Wkiom1f8mjzaktkiaahxr3omm5c043.png-wh_50 "/>
Basic Linux Learning (vii)