Use o SSHPASS combinado com o SSH. Sintaxe:
sshpass -p 'password' ssh user@domain/ip "command"
Estou escrevendo um pequeno script usando o comando expect para fornecer a senha; o objetivo é fazer login em um switch e buscar um comando. OS: RHEL 7. Há um pequeno proxychains que é usado para acessar a rede do cliente. Então, eu precisaria abrir primeiro e depois executar meus comandos (ssh etc).
Por exemplo:
[ram@abcde scripts]$ /usr/bin/proxychains ssh [email protected]
ProxyChains-3.1 (http://proxychains.sf.net)
|S-chain|-<>-129.39.159.150:1080-<>-138.222.124.15:1080-<><>-10.49.99.49:22-<><>-OK
[email protected]'s password:
Eu quero automatizar o acima usando o expect, então eu tenho abaixo o script e recebendo erros.
set user "admin"
set password "sample123"
/usr/bin/proxychains ssh [email protected]
expect "ssword: "
send "$password\r"
expect ">\r"
send "switchshow\r"
expect eof
Estou ficando abaixo do erro;
[ram@abcde scripts]$ sh br1.sh
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport] [-l login_name] [-m mac_spec]
[-O ctl_cmd] [-o option] [-p port]
[-Q cipher | cipher-auth | mac | kex | key]
[-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port]
[-w local_tun[:remote_tun]] [user@]hostname [command]
br1.sh: line 3: ProxyChains-3.1: command not found
couldn't read file "ssword: ": no such file or directory
br1.sh: line 5: send: command not found
couldn't read file ">\r": no such file or directory
br1.sh: line 7: send: command not found
couldn't read file "eof": no such file or directory
Use o SSHPASS combinado com o SSH. Sintaxe:
sshpass -p 'password' ssh user@domain/ip "command"
Tags networking expect