目录
crond:循环执行的例行性工作,每隔一定的周期就需要执行一次
2.指定在2023/08/26 09:00将时间写入testmail.txt文件中
3.指定在每天凌晨4:00将该时间点之前的系统日志信息备份到个目录下(/var/log/messages ),备份后日志文件名显示格式logfileYY-MM-DD HH-MM
(1)首先建立两台linux虚拟主机,并分别下载openssh-server软件包
第一章:例行性工作
1.atd和crond两个任务管理程序的区别
atd:单一执行的例行性工作,仅处理执行一次就结束。
①直接敲命令at HH:mm或YYYY-MM-DD 任务
②at now + number minutes/hours/days/weeks/years
③编辑任务脚本vim file
at -f file now + 2minutes 执行任务
④删除任务
atrm jobid/at -d/删除任务文件
crond:循环执行的例行性工作,每隔一定的周期就需要执行一次
①crontab -e 进入编辑模式在当前用户下执行任务
分时日月周
②vim /etc/crontab 编辑配置文件对所有用户可读任务
③删除任务
直接在配置文件中删除任务项
2.指定在2023/08/26 09:00将时间写入testmail.txt文件中
[root@server ~]# at 19:00 2023-03-29
at: refusing to create job destined in the past
[root@server ~]# at 19:00 2023-03-29
at: refusing to create job destined in the past
[root@server ~]# at 19:00 2023-04-02
warning: commands will be executed using /bin/sh
at> date >> /root/testmail.txt
at> <EOT>
job 5 at Sun Apr 2 19:00:00 2023
3.指定在每天凌晨4:00将该时间点之前的系统日志信息备份到个目录下(/var/log/messages ),备份后日志文件名显示格式logfileYY-MM-DD HH-MM
[root@server ~]# vim /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
00 04 * * * root cp/var/log/messages /logfile`date +%F%T`;echo > /var/log/messages
4.写出linux主机之间ssh免密登陆的过程
(1)首先建立两台linux虚拟主机,并分别下载openssh-server软件包
[root@sc ~]# cd /etc/yum.repos.d
[root@sc yum.repos.d]# vim /etc/yum.repos.d/base.repo
[base]
name=base
baseurl=file:///mnt/BaseOS
gpgcheck=0
[app]
name=appstream
baseurl=file:///mnt/AppStream
gpgcheck=0
[root@sc yum.repos.d]# mount /dev/sr0 /mnt
mount: /mnt: /dev/sr0 已挂载于 /run/media/root/RHEL-9-1-0-BaseOS-x
[root@sc yum.repos.d]# yum install openssh-server -y
正在更新 Subscription Management 软件仓库。
无法读取客户身份
本系统尚未在权利服务器中注册。可使用 subscription-manager 进行注册。
上次元数据过期检查:0:01:52 前,执行于 2023年07月08日 星期六 22时15
软件包 openssh-server-8.7p1-24.el9_1.x86_64 已安装。
依赖关系解决。
无需任何处理。
完毕!
(2)再编辑配置文件
[root@sc yum.repos.d]# vim /etc/ssh/sshd_config
自定义端口
Port 2222
允许root用户远程连接
#PermitRootLogin prohibit-password
PermitRootLogin yes
开启秘钥验证
PubkeyAuthentication no
(3)关闭防火墙和selinux 重启服务
[root@sc yum.repos.d]# systemctl stop firewalld
[root@sc yum.repos.d]# setenforce 0
[root@sc yum.repos.d]# systemctl restart sshd
(4)实现公钥验证
①Client端:
[root@sc ~]# hostname client
[root@sc ~]# bash
生成密钥对:
[root@client ~]# ssh-keygen -t RSA
Generating public/private RSA key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:Zh6wyl56LZOUasrQJo8e3ATEeFoYGB+U7JqGCKXrZ/o root@client
The key's randomart image is:
+---[RSA 3072]----+
|*Bo. |
|=o*. |
| O. . |
|+ o o |
|++ . ..S |
|Boo. .o+ . |
|=oo.oo.o. |
| O.+oo= . |
|ooOEo. o |
+----[SHA256]-----+
查看生成的公私钥:
[root@client ~]# ll /root/.ssh
总用量 8
-rw-------. 1 root root 2590 7月 8 22:42 id_rsa
-rw-r--r--. 1 root root 565 7月 8 22:42 id_rsa.pub
将client端公钥发送给server端:
[root@client ~]# ssh-copy-id 192.168.248.133
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.248.133 (192.168.248.133)' can't be established.
ED25519 key fingerprint is SHA256:kCGpgHh4BG2LP3iB/4NO/8WNr3tJlmex1zv1NdaJwJ8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.248.133's password:
123Permission denied, please try again.
root@192.168.248.133's password:
Permission denied, please try again.
root@192.168.248.133's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.248.133'"
and check to make sure that only the key(s) you wanted were added.
②Server端:
[root@localhost ~]# hostname server
[root@localhost ~]# bash
[root@server ~]# ll /root/.ssh
如果没有.ssh文件需要创建一个
[root@server ~]# mkdir /root/.ssh
(5)验证成功,实现连接:
[root@server ~]# ssh 192.168.248.133
The authenticity of host '192.168.248.133 (192.168.248.133)' can't be established.
ED25519 key fingerprint is SHA256:kCGpgHh4BG2LP3iB/4NO/8WNr3tJlmex1zv1NdaJwJ8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.248.133' (ED25519) to the list of known hosts.
root@192.168.248.133's password:
Activate the web console with: systemctl enable --now cockpit.socket
Register this system with Red Hat Insights: insights-client --register
Create an account or view all your systems at https://red.ht/insights-dashboard
Last failed login: Sat Jul 8 22:43:53 CST 2023 from 192.168.248.133 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Sat Jul 8 22:09:39 2023 from 192.168.248.1
[root@client ~]#