Linux 无root权限自动登陆脚本

  • Post author:
  • Post category:linux


tcl下载:

链接:https://pan.baidu.com/s/159vFkd4dkkIuuEHUP7zACg

提取码:xw1j

expect下载:

链接:https://pan.baidu.com/s/1MdCPZUs0XhcMNBgmzFEbhg

提取码:1xom

cd /home/whop

tar zxvf tcl8.4.19-src.tar.gz

cd /home/whop//tcl8.4.19/unix
./configure --prefix=$HOME
make && make install

cd /home/whop

tar zxvf expect5.45.tar.gz

cd /home/whop/expect5.45
./configure --prefix=$HOME
make && make install

vi autologin.sh

#!/bin/bash 
while true ;do
read -p "please input the ip:128,129,130: " variable
case $variable in
"128" )
host="10.213.83.128"
passwd="A13@xy111j"
break
;;
"129" )
host="10.213.83.129"
passwd="Azz13@xyj"
break
;;
"130" )
host="10.213.83.130"
passwd="Azz113@xyj"
break
;;
*)
echo "input error,please try again"
;;
esac
done

/home/whop/hkh/sh/login.sh sxsgin $host $passwd

vi login.sh

#! /home/whop/bin/expect
#user第一个参数
set user [lindex $argv 0]
#host第二个参数
set host [lindex $argv 1]
set passwd [lindex $argv 2]
#set passwd "7p!Gsk$"
#cm第三个参数,也就是要执行的命令
#set cm [lindex $argv 2]
spawn ssh $user@$host
expect {
"*yes/no" {send "yes\r";exp_continue}
"*assword:" {send "$passwd\r"}
}
interact


vi ~/.bash_profile

alias logto='sh /home/whop/hkh/sh/autologin.sh'


source ~/.bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH
export JAVA_HOME=/home/sxsgin/jdk1.8.0_221
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}



版权声明:本文为hongkaihua1987原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。