1.Client端执行如下命令,全程不需要输入任何东西
ssh-keygen -t rsa
2.拷贝Client上生成的公钥到服务器
scp -p /root/.ssh/id_rsa.pub root@250.250.250.250:/root/.ssh/
3.把client公钥信息保存到authorized_keys
cat id_rsa.pub >>authorized_keys
4.拷贝服务器文件到本地
scp -r root@250.250.250.250:/123.txt /home/backup
5.编写shell脚本
echo "Hello world" time=$(date +"%Y-%m-%d") scp -r -C root@123.456.789.111:/wwwroot /home/backup/$time date >> /home/backup/res.log echo 'success' >> /home/backup/res.log echo '---------------------------' >> /home/backup/res.log SevenDays=$(date -d -7day +"%Y-%m-%d") if [ -d /home/backup/$SevenDays ] then rm -rf /home/backup/$SevenDays date >> /home/backup/res.log echo 'delete success' >> /home/backup/res.log else echo "file not exist" echo "bash complete" fi
6.定时任务执行shell脚本
0 18 * * * sh /root/down.sh