Error in spawn and expect for password

Code Broken!!

"cod generator ip=$loja"

expect -c "
# set timeout -1
set timeout 18
spawn scp -C /etc/samba/arkivo.sh root@$loja:/etc/samba/
expect { -re "*yes/no*"{ send "yes\r"
exp_continue }
-re "*password:*" {
send "senha\r"
expect \"*#*\"}}
ssh root@$loja
expect \"*password:*\"
send \"senha\r\"
expect \"*#*\""
cd /opt/
chmod +x arkivo.sh
./arkivo.sh
"

"interactive password authentication" means "password typed by a human being in realtime authentication" and no substitutes for humans are acceptable to ssh. To arrange automatic logins, use ssh keys.

I using sshpass for authentication

No you are not. You are kludging passwords into scp with the expect brute-forcing tool. You wouldn't need it at all if you used ssh/scp/sftp as they were intended to be used -- it would work in a single line, unattended.

sshpass is also a terrible idea. Putting passwords on the commandline leaves them wide open to be viewed by snoopers.

2 Likes

Thank you Corona, I will make the ssh_keys:D.