Passwordless Login

Viewed 1268

Problem statement

I want to access a server without asking me the password (will be mentioned in the script) and run a command on that server.

My Code

#!/usr/bin/expect
spawn sudo su - <server_name>
expect "[sudo] password for chronicles:"
set Password "xxxxxxx"
send "$Password\r"
#set timeout 300
send "whoami\r"
send "ls -ltr\r"
expect eof

Output

invalid command name "sudo"
    while executing

Restrictions

  • I dont have access rights to change env variables or modify .bash_profile / .bashrc.
  • su server_name command not allowed
3 Answers
Related