当前位置:首页 » 网页前端 » 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"

这样试试