zoukankan      html  css  js  c++  java
  • ssh-pass 使用无需输入密码

    在Linux后台中,经常会用到ssh、scp等命令。需要进行认证,手动输入密码,是交互式的过程。
    当将ssh、scp等命令做成自动化脚本时,可能需要非交互式的登录过程,此时可以用sshpass。

    安装方式

    1.在基于 RedHat/CentOS 的系统中,首先需要启用 EPEL 仓库并使用 yum 命令安装它。
    # yum install sshpass
    2.在 Debian/Ubuntu 和它的衍生版中,你可以使用 apt-get 命令来安装。
    $ sudo apt-get install sshpass
    3.mac环境
    brew install sshpass
    4.另外,你也可以从最新的源码安装 sshpass,首先下载源码并从 tar 文件中解压出内容:
    $ wget http://sourceforge.net/projects/sshpass/files/latest/download -O sshpass.tar.gz
    $ tar -xvf sshpass.tar.gz
    $ cd sshpass-1.06
    $ ./configure
    # sudo make install 

    使用举例

    使用-p参数指定登录密码

    # 免密码登录
    $ sshpass -p password ssh username@host
    
    # 远程执行命令
    $ sshpass -p password ssh username@host <cmd>
    
    # 通过scp上传文件
    $ sshpass -p password scp local_file root@host:remote_file 
    
    # 通过scp下载文件
    $ sshpass -p password scp root@host:remote_file local_file
  • 相关阅读:
    队列 和 线程 之GCD dispatch
    ios NSUserDefaults存储数据(偏好设置)
    Binary Tree postorder Traversal
    Binary Tree Inorder Traversal
    Binary Tree Preorder Traversal
    Rotate List
    Reversed Linked List(Reverse a singly linked list)
    Remove Element
    Swap Nodes in Pairs
    Add Two Numbers
  • 原文地址:https://www.cnblogs.com/zhaoyingjie/p/13045202.html
Copyright © 2011-2022 走看看