當前位置:首頁 » 網頁前端 » shell怎麼登錄腳本
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

shell怎麼登錄腳本

發布時間: 2022-01-13 12:42:12

Ⅰ shell腳本 ,在linux 下運行一個shell腳本登陸遠程unix 伺服器,請問這個腳本如何寫

#!/bin/bash
tmptty=`tty`
tmptty=`basename $tmptty`
tmpname=`whoami`
ip="xxx" #目標主機地址
inp1="xxx^M" #主機的用戶名,,注意必須有^M
inp2="xxx^M" #主機的密碼,注意必須有^M
inp3="ls^M"
inp4="pwd^M"
inputfile=in
outputfile=out.log
rm -fr $inputfile
rm -fr $outputfile
mknod $inputfile p
touch $outputfile
#file description 7 for out and 8 for in
exec 7<>$outputfile
exec 8<>$inputfile
telnet $ip <&8 >&7 &
sleep 2; echo $inp1 >> $inputfile
sleep 2; echo $inp2 >> $inputfile
sleep 2; echo $inp3 >> $inputfile
sleep 2; echo $inp4 >> $inputfile
tail -f $outputfile &
while true
do
read str
if [[ $str = "quit" || $str = "exit" ]]
then echo $str >> $inputfile exit
else echo $str >> $inputfile
fi
done
ps -ef | grep telnet | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh
ps -ef | grep tail | grep -v grep | grep -v telnetd | grep $tmptty | grep $tmpname | awk '{print " kill -9", $2}' | sh

Ⅱ shell腳本通過ssh登錄到伺服器進行操作

#命令用;號或&&分割沒錯,但需要加上"號即可。
#來自:DZ動力(verydz.com)
ssh59.43.50.82"gunzip/export/home/kaohe/tmp/$name/*.gz;/iteview/youwenjie/work.sh"

Ⅲ unix主機怎樣寫個shell腳本用ssh 登錄其他主機 知道密碼 ip 用戶名 (也就是直接把密碼寫在shell里)

不可能的,這個思路可以扔掉了。
如果是telnet還有方法
ssh,做密鑰吧。別想在腳本里寫了。

Ⅳ 如何使用shell腳本修改linux的登陸密碼

以root用戶為例:
第一種:
echo 「123456″ | passwd –stdin root
優點:方便快捷
缺點:如果你輸入的指令能被別人通過history或者其他方式捕獲,那麼這樣的方式是很不安全的,更重要的是如果密碼同時含有單引號和雙引號,那麼則無法通過這種方法修改。
說明:
批量修改linux密碼 passwd –stdin user 從標准輸入中讀取密碼,所以用戶可以在腳本中使用如 echo NewPasswd | passwd –stdin username 這種方式來批量更改密碼 但在其它的一些發行版(如Debian/Suse)所提供的passwd並不支持–stdin這個參數
第二種:
a. 首先將用戶名密碼一起寫入一個臨時文件.
cat chpass.txt
root:123456
zhaohang:123456
b. 使用如下命令對用戶口令進行修改:
chpasswd < chpass.txt
c. 可以使用 123456 來登錄系統,密碼修改完畢.
優點:可以很快速方便的修改多個用戶密碼
缺點:明文密碼寫在文件里仍然顯得不夠安全,但是避免了第一種修改方式不能有特殊字元串密碼的情況.
第三種:
a. 用 openssl passwd -1 來生成用戶口令,連同用戶名一起寫入文件.
cat chpass.txt
root:$1$ri2hceVU$WIf.firUBn97JKswK9ExO0
zhaohang:$1$i/Gou7.v$Bh2K6sXmxV6/UCxJz8N7b.
b. 使用如下命令對用戶口令進行修改:
chpasswd -e < chpass.txt
c. 可以使用 123456 來登錄系統,密碼修改完畢.

Ⅳ shell 腳本模擬用戶登入

加個計數器:

#/bin/bash
date=$(date)
ip=`whoami|awk'{print$5}'|cut-d"("-f2|cut-d")"-f1`
read-p"Loginas:"ID
read-p"$ID@"$ip"'spassword:"PASS
retry=4
until[$ID=="root"-a$PASS=="123"]||[$retry-eq"0"]
do
echo"Accessdenied"
read-p"$ID@"$ip"'spassword:"PASS
retry=$((retry-1))
done
echo"Lastlogin:"$date"from"$ip""

Ⅵ Shell下,如何實現自動登錄

要帶跳過輸入密碼的環節么?
如果你想每次鏈接的時候自己手動輸入密碼,那就參考這樣寫
#!/bin/bash
ip=$1
ssh 用戶名@ip地址 -p埠號

保存後給執行許可權,運行時在腳本後面直接跟一個IP地址

如果你想每次鏈接的時候自動跳過輸入密碼的環境,那就再網路下「ssh建立信任關系」,腳本依然還是這個腳本,只是登陸的時候做了互相信任的話,就不需要密碼了

Ⅶ shell腳本編寫用戶登錄

寫個腳本文件:#!/bin/bashfindlog=`find/-name*.log`cp$findlog/home/log/

Ⅷ 如何編寫一個shell腳本,可以自動從伺服器A登陸到伺服器B,並在伺服器B上執行一個操作

expect -c "
set timeout 30;
spawn /usr/bin/ssh admin@$ServerB-IP
expect {
\"*yes/no*\" {send \"yes\r\"; exp_continue}
\"*password*\" {send \"xxx\r\";}

expect {
\"*# \" {send \"tar zcvf ~/hello.tar.gz hello\r\"}
\"*$ \" {send \"tar zcvf ~/hello.tar.gz hello\r\"}
}
interact"

這樣試試