ssh配置免密登入+rsync免密同步文件

 

ssh配置免密登入

1、root用户登入,并创建test账号

        useradd test -d /home/userhome/test
        修改密码
        passwd test

2、test账号登入生成SSH密钥

        [test@xxxxxxxxxxx ~]$ ssh-keygen 
        Generating public/private rsa key pair.
        Enter file in which to save the key (/home/userhome/test/.ssh/id_rsa): 
        Created directory '/home/userhome/test/.ssh'.
        Enter passphrase (empty for no passphrase): 
        Enter same passphrase again: 
        Your identification has been saved in /home/userhome/test/.ssh/id_rsa.
        Your public key has been saved in /home/userhome/test/.ssh/id_rsa.pub.
        The key fingerprint is:
        SHA256:xxxxxxxxxCkBXX/i9JQMHGioopTrI test@xxxxxxxxxxx
        The key's randomart image is:
        +---[RSA 2048]----+
        | . o....o.o*..oxx|
        |  = ... .+..=  =-|
        | P o .  o..  .oo*|
        |    .    +  .o----|
        |        S +...+o+|
        |         o oo o+.|
        |          o. o . |
        |         . ..    |
        |          .      |
        +----[SHA256]-----+

3、将SSH公钥复制到客户机        

        说明:客户机192.168.1.81上面创建guest账号
        [test@xxxxxxxxxxx ~]$ ssh-copy-id guest@192.168.1.81 -p 22
        /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/userhome/test/.ssh/id_rsa.pub"
        The authenticity of host '192.168.1.81 (192.168.1.81)' can't be established.
        ECDSA key fingerprint is SHA256:+aRrV/sdfsdfsdfsdfsdfmhHNhbKb7g.
        ECDSA key fingerprint is MD5:xxxxxxx.
        Are you sure you want to continue connecting (yes/no)? 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
        guest@192.168.1.81's password: 
        
        Number of key(s) added: 1
        
        Now try logging into the machine, with:   "ssh -p '22' 'guest@192.168.1.81'"
        and check to make sure that only the key(s) you wanted were added.

4、免密登入192.168.1.81客户机

        [test@xxxxxxxxxxx ~]$ ssh guest@192.168.1.81 -p 22 -v
          Welcome to xx xx xx Compute Service !

         加上-v 可以调试ssh,尤其遇到登入不了的问题时

5、本机也可以配置免密登入 

    
        5.1、拷贝公钥
            ssh-copy-id test@127.0.0.1 -p 22
        5.2、直接登入
            ssh test@127.0.0.1 -p 22 


  6、退出登入       

        exit

rsync 通过ssh免密码方式同步文件    

    rsync -avz -e "ssh -p 22"  ~/test.txt  guest@192.168.1.81:/home/userhome/test/
   
    rsync -avz -e "ssh -p 22" ~/test.txt  test@127.0.0.1:/home/userhome/test/

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值