First install expect in your local machine.
For ubuntu : apt-get install expect.
For Centos : yum install expect.
Create a file sshlogin
chmod +x sshlogin
#!/usr/bin/expect
set timeout 10
log_user 0
spawn ssh -p 1707 sshadmin@ipaddress
expect "*?assword:*"
send -- "sshadminPassword\r"
expect "*sshadmin@*"
send "su -\n"
expect "*?assword:*"
send -- "rootPassword\r"
send "uptime\n"
interact
1. Where 1707 is the ssh port,
2. ipaddress is the IP address of your server to which you need to login.
3. Replace "sshadminPassword" with your sshadmin password.
4. Replace "rootPassword" with your root password.
5. uptime is the command to execute after login to the server. You can give any command here.
You can also try (MTputty) in Windows machine for this purpose.
After installing the Mtputty
Go to Server Menu >> Add Server >> Script Tab
Enter the below code :
###_SLEEP:10000
sshadmin
###_SLEEP:2000
sshadmnpassword
###_SLEEP:10000
su - root
###_SLEEP:2000
rootpassword
###_SLEEP:200
1. Replace sshadminpassword with your sshadmin password.
2. Replace rootpassword with your root password.
Comments