美文网首页
2018-10-09 ssh 免密登录以及备份

2018-10-09 ssh 免密登录以及备份

作者: e8a37405cb53 | 来源:发表于2018-10-09 10:14 被阅读0次

    服务器 A

    ssh-keygen -t rsa
    # generate id_rsa.pub, copy it to server B
    

    服务器 B,

    mv id_rsa.pub  ~/.ssh/authorized_keys 
    # 如果有多个服务器连接 cat  id_rsa.pub >>  ~/.ssh/authorized_keys
    # cat  ~/.ssh/id_rsa.pub >>  ~/.ssh/authorized_keys
    chmod 700 ~/.ssh/
    chmod 600 ~/.ssh/authorized_keys 
    

    这样 服务器 A就可以免密登录服务器B

    ssh nong@222.200.186.169
    

    反之亦然~

    备份, rsync 进行备份, crontab 定时执行
    vim /data2/nong/bak_161/crontab.txt

    0 2 * * *  rsync -av -l -e ssh nong@222.200.186.161:/public/home/nong/webs/ /data2/nong/bak_161/webs
    0 2 * * *  rsync -av -l -e ssh nong@222.200.186.161:/public/home/nong/pipeline /data2/nong/bak_161/pipeline
    0 2 * * *  rsync -av -l -e ssh nong@222.200.186.161:/public/home/nong/python /data2/nong/bak_161/python
    
    • -l, --links copy symlinks as symlinks

    The first part is "0 2 * * *". This is where we schedule the timer.
    The rest of the line is the command as it would run from the command line.

    image.png

    加入schedule

    crontab crontab.txt 
    crontab -l
    

    设置远程主机别名
    vim ~/.ssh/config

    Host jhd
    HostName 1xx.1xx.1xx.67
    User root
    IdentitiesOnly yes
    

    其中:

    1. Host 后边的是名称,以后可以根据这个名称进行访问;
    2. HostName是你的主机IP地址;
    3. User为主机登录的用户名;
    4. IdentitiesOnly yes固有配置;

    相关文章

      网友评论

          本文标题:2018-10-09 ssh 免密登录以及备份

          本文链接:https://www.haomeiwen.com/subject/ygceaftx.html