Shell命令sshpass非互動SSH密碼驗證,sshpassssh

來源:互聯網
上載者:User

Shell命令sshpass非互動SSH密碼驗證,sshpassssh

Shell命令sshpass非互動SSH密碼驗證

#安裝sshpasssshpass

:http://sourceforge.net/projects/sshpass/ 

下載為一個 tar.gz的壓縮包。

$ tar -zxvf sshpass-1.05.tar.gz

$ cd sshpass-1.05

$ ./configure --prefix=/opt/sshpass

 #指定安裝目錄

$ make

$ make install

$ cp /opt/sshpass/bin/sshpass /usr/bin/

安裝完成

#查看協助

sshpass -h

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


   -h            Show help (this screen)

   -V            Print version information

At most one of -f, -d, -p or -e should be used



#!/bin/bash

cd $(dirname $0)

source ./config.sh

date=`date +%Y-%m-%d`

#上傳DUMP指令碼到服務端

sshpass -pyour_pwd scp -P22 ./dump.sh your_user@192.168.1.10:~/

#-o StrictHostKeyChecking=no 避免第一次登入出現公開金鑰檢查。

sshpass -pyour_pwd scp -o StrictHostKeyChecking=no -P22 ./dump.sh your_user@192.168.1.10:~/

#登陸到服務端地址,執行DUMP指令碼,將執行結果寫入本地檔案

sshpass -pyour_pwd ssh -p22 your_user @192.168.1.10 "sh ~/dump.sh" >local_result.txt

#使用檔案中的密碼

sshpass -f pwd.file ssh -p22 your_user@192.168.1.10 "sh ~/dump.sh" >>local_result.txt

#從環境變數(SSHPASS)讀取密碼

sshpass -e ssh -p22 your_user@192.168.1.10 "sh ~/dump.sh" >>local_result.txt


linux下怎使用shell指令碼進行ssh遠程登陸到其他機器執行停止進程的命令 使用者名稱/密碼:test/12345h

ssh test@10.1.1.8 輸入密碼,登陸成功後
ps -ef 查看進程pid
或者 netstat -ntpl
kill -9 進程pid
 
python調用shell命令時 有時要使用者手動輸入密碼(如ssh),Python要然Python程式輸入密碼

expect專門幹這個de
網路一搜,資料很多,本人做過這個,好使 大致如下
expect
spawn ssh 192.168.1.1
expect "login:"
send "wuhuhu"
expect "Pasword:"
send "123456"
 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.