linux下ssh登陸遠端執行命令

2021-06-05 17:49:41 字數 1419 閱讀 7584

#!/usr/bin/expect

set timeout 20

send_user "please enter password to run:"

expect "gogogo\n"

set hosta 10.27.4.21

set hostb 10.27.4.33

set hostc 10.27.4.201

set name root

set passworda *****

set passwordb *****

spawn ssh $hosta -l $name

expect

"assword:"

}expect "*#"

send "cd /etc/sysconfig/network-scripts/\n"

expect "*#"

send "sed -i 's/$hosta/$hostc/' ifcfg-eth0\n"

expect "*#"

send "service network restart\n"

expect "*#"

send "exit\n"

expect "*#"

spawn ping $hostc -c 5

expect

"*reachable"

} expect "*#"

send "cd /etc/sysconfig/network-scripts/\n"

expect "*#"

send "sed -i 's/$hostb/$hosta/' ifcfg-eth0\n"

expect "*#"

send "service network restart\n"

expect "*#"

send "exit\n"

expect "*#"

spawn ping $hosta -c 5

expect

"*reachable"

}spawn ssh $hostc -l $name

expect

"assword:"

}expect "*#"

send "cd /etc/sysconfig/network-scripts/\n"

expect "*#"

send "sed -i 's/$hostc/$hostb/' ifcfg-eth0\n"

expect "*#"

send "service network restart\n"

expect "*#"

send "exit\n"

expect "*#"

spawn ping $hostb -c 5

expect

"*reachable"

}expect eof

SSH遠端登陸

ssh是一種網路協議,用於計算機之間的加密登陸。windows putty linux openssh 第一次登陸對方主機,系統會出現如下提示,表示無法確認host主機的真實性,只知道公鑰指紋,是否繼續連線 ssh user host the authenticity of host host 19...

ssh遠端登陸

一 應用場景 有一台linux伺服器,現在需要通過linux作業系統或者windows作業系統遠端登陸這台伺服器。二 linux 遠端登入linux伺服器 ubuntu為例 1 首先,伺服器端需要安裝ssh伺服器,方法為 sudo apt get updatesudo apt get install...

Linux下免密碼登陸ssh

第一步 ssh keygen 建立公鑰和金鑰 ssh keygen t rsa 第二步 複製到伺服器jiandq100 ssh copy id 把本地主機的公鑰複製到遠端主機的authorized keys檔案上。ssh copy id i jiandq101 這樣你就可以直接從伺服器jiandq1...