zoukankan      html  css  js  c++  java
  • sshpass笔记

    sshpass简介

    ssh登录的时候使用的是交互式输入,不能预先在命令行使用参数指定密码,sshpass就是为了解决这个问题的。sshpass提供非交互式输入密码的方式,可以用在shell脚本中自动输入密码。

    比如在执行ssh、scp、rsync等命令时可以使用sshpass来实现预先指定密码。

    安装

    CentOS使用yum安装即可:

    yum install sshpass

    使用

    -p指定明文密码

    使用-p选项在ssh登录的时候指定明文密码:

    sshpass -p nopasswd ssh root@localhost

    使用-p选项在拷贝文件的时候指定密码:

    sshpass -p nopasswd scp root@localhost:~/free_buff.sh /usr/bin

    指定明文密码的方式简单方便,但是密码容易暴露,比如登录到某台机器上执行一个命令:

    sshpass -p nopasswd ssh root@localhost 'sleep 1024'

    然后使用ps -ef查看:

    image

    哈,密码打码了...

    -e从环境变量读入密码

    如果不想明文指定密码的话,可以先将密码设置到一个叫做SSHPASS的环境变量中,然后使用-e选项它就会自己去这个变量中取密码。

    比如:

    export SSHPASS=nopasswd
    sshpass -e ssh root@localhost 'sleep 10'

    sshpass会自动去名为SSHPASS的变量中读到密码nopasswd,然后使用这个密码来作为后面ssh的登录密码。

    -f从文件读取密码

    使用-f指定从一个文件中读取密码,比如:

    sshpass -f /root/shell/passwd_file ssh root@localhost 'echo ok'

    sshpass指定时会去读取/root/shell/passwd_file的内容,然后将读到的内容当做后面ssh的密码输入。

    从标准输入读取密码

    如果没有使用-f/-d/-p/-e中的任何一个,那么将从stdin读入密码。

    sshpass  ssh root@localhost 'echo ok'

    帮助手册

    Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
       -f filename   Take password to use from file
       -d number     Use number as file descriptor for getting password
       -p password   Provide password as argument (security unwise)
       -e            Password is passed as env-var "SSHPASS"
       With no parameters - password will be taken from stdin
    
       -P prompt     Which string should sshpass search for to detect a password prompt
       -v            Be verbose about what you're doing
       -h            Show help (this screen)
       -V            Print version information
    At most one of -f, -d, -p or -e should be used
    

    .

  • 相关阅读:
    如何通过jQuery获取一个没有定高度的元素---------的自适应高度(offsetHeight的正确使用方法)
    jQuery插件之----缓冲运动
    jQuery插件学习基础
    javascript随机一个1-9的数字
    jQuery事件之鼠标事件
    枚举类的应用
    ConvertUtils.register(new DateConverter(null), java.util.Date.class)使用
    逆向工程不使用驼峰命名而保持字段中下划线
    mongoDB 的介绍
    eclipse 的版本及下载地址
  • 原文地址:https://www.cnblogs.com/cc11001100/p/7979544.html
Copyright © 2011-2022 走看看