第一種:
ftp -v -n 192.168.0.1 21 <<!user ftp ftp123bay!
第二種:
{ echo -e "/n" echo -e "ifconfig" }| telnet 0 1234
第三種:
ssh 192.168.0.2 '/etc/init.d/httpd start'
第一種方式最麻煩,比較喜歡第二種,第三種方式最簡單,你覺得呢?
如果覺得好就收藏吧! 如果還有其他方式,請留言告訴我,謝謝。
第四種:
#!/usr/bin/expect -fset port 22set user rootset host 192.168.0.1set passWord rootspawn ssh -D $port $user@$host#root@192.168.0.1's password:expect "*assword:*"send "$password/n"spawn ifconfiginteractexpect eof
send:用于向進程發送字符串expect:從進程接收字符串spawn:啟動新的進程interact:允許用戶交互第四種交互方式怎么樣?如何從服務器A上ssh到服務器B上,然后執行服務器B上的命令?聽起來是不是很海派呢!案例:(獲取服務器Bifconfig保存文件,scp到服務器A)
#!/usr/bin/expect -fset port 22set user rootset host 192.168.1.2set password rootset timeout -1spawn ssh $user@$hostexpect {"*yes/no" { send "yes/r"; exp_continue}"*assword:" { send "$password/r" }}expect "*#*"send "ifconfig > /home/cfg /r"send "exit/r"interactspawn scp $host:/home/cfg ./expect {"*yes/no" { send "yes/r"; exp_continue}"*assword:" { send "$password/r" }}expect eof
第五種:
sshpass -p root ssh 192.168.48.73 "w"
但需要安裝sshpass
下載:sshpass-1.05.tar.gz
百度去吧。
新聞熱點
疑難解答