计划任务 ssh scp

一次性调度 at

语法: at <时间格式>

at 1:00 
at 3am
at 4pm
at 16:00
at 20:00
at now +5min
at 8:00 2023-10-01

退出ctrl+d

查看一次性任务

atq

删除一次性任务 

atrm id

查看具体的计划任务

# cd /etc/spool/at

# at 4pm  at 12:30 +3[day|min|hour|month|year|week]
at 4pm 2023-09-03

批量的一次性计划任务

# vim tom.txt

useradd u99 
useradd u00 
touch /a.txt

# at 20:33 < tom.txt  输入重定向

循环调度执行cron

安装软件

    #  yum -y install crontabs    

启动服务:

 rhel7:
  #   systemctl start crond.service   ---开启服务
  #   systemctl status crond.service    ---查看状态
  #   systemctl enable crond.service   ----开机自启

查看服务状态

# systemctl status crond.service

存储位置:

cd /var/spool/cron


at的存储位置在/var/spool/at

管理方式

编辑任务计划

crontab -e   编辑当前用户的计划任务

进入后
* * * * *  + 命令  

 分钟	  小时	       日		 月		  周		   执行的命令,最好是命令的绝对路径
 0-59	  0-23  	  1-31       1-12	  0-7

 * * * * *  是每分钟

*/1 * * * *  是每隔一分钟
* */1 * * *  每隔一小时
 日和周同时设置,碰到哪个执行哪个

举例:

00 00 * * * 			#每天凌晨

00 02 * * * 		            #每天2:00整 

00 02 1 * * 			        #每月1号2:00整 

00 02 14 2 *                    #每年2月14号2:00整

00 02 * * 7 			        #每周日2:00整 

00 02 * 6 5 			        #每年6月的周五2:00整

00 02 * * * 		            #每天2:00整 

*/5 * * * * 				        #每隔5分钟 

00 02 1,5,8 * * 		                #每月1,5,8号的2:00整 

00 02 1-8 * *                     #每月1到8号的2:00整

列出任务计划

 # crontab -l

删除任务计划

# crontab -r

一个网站写完crontab可以去核对:Crontab.guru - The cron schedule expression editor

ssh

sshd服务的端口号是22

安装: 

[root@web ~]# yum -y install openssh*
启动服务
systemctl  start sshd

关闭防火墙与selinux

远程登录:需要密码

语法: ssh +对方ip  ,root 用户默认不写为root,也可以使用其他用户

[root@web ~]# ssh 10.36.192.65
The authenticity of host '10.36.192.65 (10.36.192.65)' can't be established.
ECDSA key fingerprint is SHA256:40ZcM4hvVGHFuGZn88qcQdn+IPoDZtjVou0ILkGNqGQ.
ECDSA key fingerprint is MD5:29:0a:e0:56:90:a7:b7:c2:22:41:fa:4f:af:5c:cc:b8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.36.192.65' (ECDSA) to the list of known hosts.

[email protected]'s password:    ---输入密码
Last login: Thu Sep 14 15:11:36 2023 from 10.36.192.24
[root@server ~]#     ----成功登录


退出是
[root@server ~]# exit
登出
Connection to 10.36.192.65 closed.
[root@web ~]# 

远程登录不需要密码:

1.产生公钥和私钥,一路回车即可

[root@web ~]# ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
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:hbYGZQmK9AIhGlbuUx9ZbF4p8ERhZErRb9tBBm3GNr4 root@web
The key's randomart image is:
+---[RSA 2048]----+
|=oo.  .=XX..=    |
|++.o ..oX* o X   |
|. o.o..+=.= B .  |
|  ... .o.+ o o   |
|   o   .S . o o  |
|    .  .   . E   |
|                 |
|                 |
|                 |
+----[SHA256]-----+

2.查看钥匙目录:

[root@web ~]# cd /root/.ssh/
[root@web .ssh]# ls
id_rsa  id_rsa.pub  known_hosts

id_rsa  ---私钥
id_rsa.pub  ---公钥
known_hosts  ----确认过公钥指纹的可信服务器列表的文件
authorized_keys ---授权文件,是传输过公钥到对方服务后会自动重命名生成的

3.拷贝公钥给对方机器

语法:ssh-copy-id  + 对方ip

[root@web .ssh]# ssh-copy-id 10.36.192.65
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/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
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '10.36.192.65'"
and check to make sure that only the key(s) you wanted were added.

4.下次远程连接时,就不需要输入密码

[root@web ~]# ssh 10.36.192.65
Last login: Thu Sep 14 19:34:44 2023 from 10.36.192.87
[root@server ~]# 

主机一将他的 公钥给了主机二
这样主机1登录主机二 就不需要密码了
!!!!!!

作用:

计划任务 ssh scp_第1张图片

修改端口号:

修改配置文件:

[root@web ~]# vim /etc/ssh/sshd_config 

17 #Port 22   #将注释去掉,修改端口号可以修改为自定义的。

重启服务
# systemctl restart sshd

远程登录如果修改了端口号,那么登录的时候就需要指定端口号 -p

例如:

# ssh [email protected] -p 2222

修改DNS反解析

#UseDNS yes 改为no
[root@linux-server ~]# systemctl restart sshd

作用:

计划任务 ssh scp_第2张图片

远程拷贝拿去:  scp

语法:  scp   -P   端口号  /a.txt    ip: /路径

                                         源文件      目标路径

# scp -r -P 2222 test/ 192.168.246.158:/root/

谁是远程加谁ip
远程拷贝目标机器改了端口加-(大)P 
目录加 -r

从远程服务器拿文件到本服务器上
scp root@远程ip:/目标文件路径   保存到本地的路径

计划任务 ssh scp_第3张图片

你可能感兴趣的:(centos,linux,运维)