
1.登陆linux系统,打开终端命令。输入 rpm -qa |grep ssh 查找当前系统是否已经安装
2.如果没有安装SSH软件包,可以通过yum 或rpm安装包进行安装
3、安装好了之后,就开启ssh服务。Ssh服务一般叫做 SSHD
4、命令行输入 service sshd start 可以启动 或者使用 /etc/init.d/sshd start
5、输入:ssh 账号@IP地址即可。
比如:ssh oracle@192.168.10.13
然后按照提示输入密码. 一切无误则进入该远程主机.
首先你用ssh-keygen生成公钥/私钥对,拷贝到路由器上。这样就可以免密码登录。
然后你写个脚本,用here文档来登录路由器,并进行 *** 作。
ssh 用户名@IP <<SSH
#这里写你需要的 *** 作
SSH
我比较认同“ssh之后是远程主机执行的命令本地变量不起作用”这种说法
你的脚本之所以$aaa能回显,是因为在本地定义了这个变量,但本地没有定义$i这个变量,所以无法显示变量值,把aaa="u1 u2"一块塞<<ff.......ff这个内联重定向数据中去。再试试看。
#!/bin/bashtmptty=`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 2echo $inp1 >>$inputfile
sleep 2echo $inp2 >>$inputfile
sleep 2echo $inp3 >>$inputfile
sleep 2echo $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
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)