zoukankan      html  css  js  c++  java
  • sshpass的使用方法

    author:headsen  chen     

    date : 2017-11-29  15:46:39

    notice:created  by  headsen chen himself   and not allowed to copy,or  will done by low.

     sshpass全国超级使用第一人

    应用范围:可以在命令行直接使用密码来进行远程连接和远程拉取文件。

    使用前提:对于未连接过的主机。而又不输入yes进行确认,需要进行sshd服务的优化:

    # vim /etc/ssh/ssh_config   
    StrictHostKeyChecking no
    # vim /etc/ssh/sshd_config GSSAPIAuthentication no UseDNS no

    # service sshd restart

    sshpass 命令的安装:

    # yum -y install sshpass

    实例1:直接远程连接某台主机:

    命令:sshpass -p xxx ssh root@192.168.11.11

               sshpass -p xxx ssh root@192.168.11.11 'w'  -o StrictHostChecking=no     免输入yes。

    实例:本地执行远程机器的命令:

    命令: sshpass -p xxx ssh root@192.168.11.11 "ethtool eth0"

    实例2:远程连接指定ssh的端口:

    命令:sshpass -p 123456 ssh -p 1000 root@192.168.11.11         (当远程主机不是默认的22端口时候)

     

    实例3:从密码文件读取文件内容作为密码去远程连接主机

    命令:sshpass -f xxx.txt  ssh root@192.168.11.11

     

    实例4:从远程主机上拉取文件到本地

    命令: sshpass -p '123456' scp root@host_ip:/home/test/t ./tmp/

    实例5:sshpass不可以直接接带特殊字符意义的密码,需要转义或者用小括号,或者指定文件的方式来连接都可以规避这个问题。

    附录:sshpass的安装

    Ubuntu

    apt-get  install sshpass

    centos:

    # 源码包安装
     wget http://sourceforge.net/projects/sshpass/files/sshpass/1.05/sshpass-1.05.tar.gz 
     tar xvzf sshpass-1.05.tar.gz 
     cd sshpass-1.05.tar.gz 
     ./configure 
     make 
     make install 
    
    # yum安装
    yum  -y install sshpass
  • 相关阅读:
    spring-boot整合dubbo:Spring-boot-dubbo-starter
    基于Spring的轻量级工作流框架
    Spring多种加载Bean方式简析
    Spring Dubbo 开发笔记
    基于Spring开发——自定义标签及其解析
    Navicat连接MySQL8.0亲测有效
    学习Python中遇到的各种错误
    字符串转字典
    set(待整理)
    C++中虚析构的作用
  • 原文地址:https://www.cnblogs.com/kaishirenshi/p/7921308.html
Copyright © 2011-2022 走看看