10、服务与计划任务

实验-systemctl控制服务
yum install -y httpd
systemctl status httpd
systemctl start httpd
systemctl stop httpd
systemctl restart httpd
systemctl reload httpd
systemctl enable httpd
systemctl is-enabled httpd
systemctl disable httpd
systemctl mask httpd
systemctl unmask httpd
systemctl list-dependencies httpd
systemctl list-unit-files --type service | grep http

实验-systemctl控制启动级别
systemctl get-default
systemctl isolate multi-user.target
systemctl set-default multi-user.target
systemctl list-unit-files --type target | grep runleve
systemctl isolate runlevel3.target

实验-ssh基本操作
在qin1上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.1/24

在qin2上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.2/24
ssh 192.168.100.1
ssh qin@192.168.10.1
scp /etc/fstab 192.168.100.1:/root/Desktop/
scp /etc/fstab qin@192.168.100.1:/tmp/
scp -r 192.168.100.1:/home/ /tmp/

实验-ssh禁止root直接登录
在qin1上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.1/24
vim /etc/ssh/sshd_config
PermitRoot no #激活并修改
systemctl restart sshd.service

在qin2上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.2/24
ssh 192.168.100.1 #权限拒绝
ssh qin@192.168.100.1

实验-ssh免密码登录
在qin2上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.1/24
useradd qin2
echo qin2 | passwd --stdin qin2

在qin1上
systemctl stop firewalld.service
setenforce 0
ifconfig eno16777736 192.168.100.1/24
useradd qin1
echo qin1 | passwd --stdin qin1
su - qin1
ssh-keygen #不要输入passphrase
ssh-copy-id qin2@192.168.100.2
ssh qin2@192.168.100.2
#建议将qin2的sshd_config文件的PasswordAuthentication值改为no,禁止用户通过密码认证

实验-一次性计划任务
systemctl status atd.service
at 1am monday
/usr/bin/cat /dev/null > /var/log/message
ctrl+d
atq1
atrm 1
echo qin >> /etc/at.deny
su - qin
at 18:00 #无权使用at

实验-周期性计划任务
vim qin.sh
#!/bin/bash
/usr/bin/touch /crontest
chmod a+x qin.sh

systemctl status crond.service
crontab -e -u root
30 2 */1 * * systemctl restart httpd
30 2 */1 * * /root/Desktop/qin.sh
crontab -l -u root
crontab -r -u root

echo qin >> /etc/cron.deny
su - qin
crontab -e #不允许使用此程序

posted @ 2023-10-27 21:02  old_bird  阅读(8)  评论(0编辑  收藏  举报