I have a bash script to copy a file to a remote server using scp
and expect
. The script is as follows:
#!/usr/bin/expect -f
set port [lindex $argv 0]
set file_to_send [lindex $argv 1]
set login [lindex $argv 2]@[lindex $argv 3]
set username [lindex $argv 2]
set hostname [lindex $argv 3]
set password [lindex $argv 4]
set dest_folder [lindex $argv 5]
spawn scp -P $port $file_to_send $login:$dest_folder
expect {
# this will loop forever
# {*fingerprint*}
# sleep 0.8
{Are you sure you want to continue connecting (yes/no/\[fingerprint\])?}
{
exp_send "yes\r"
exp_continue
}
{password:} {send "$password\r"}
}
expect eof
I want to get the initial prompt, given when my machine has never connected to the remote server. Thus, I have tried both removing the added key inside known_hosts
or that whole file in my machine. However, I cannot get the initial prompt anymore. This doesn't happen on another machine. Either method gives me the initial prompt as expected. Why is this happening? What can I do to get what I want?
The outpout of grep -i StrictHostKeyChecking ~/.ssh/config /etc/ssh/ssh_config
on all 3 machines is:
grep: /home/ubuntu/.ssh/config: No such file or directory
/etc/ssh/ssh_config:# StrictHostKeyChecking ask
grep -i StrictHostKeyChecking ~/.ssh/config /etc/ssh/ssh_config
? Please edit the question and add information.StrictHostKeyChecking
is commented out, but the default value isask
anyway. OK. (2) "I have tried both removing the added key insideknown_hosts
or that whole file in my machine." – Checkman 5 ssh_config
,GlobalKnownHostsFile
andUserKnownHostsFile
. Not only one can use another file; one can use many files (the default setup uses four in total). So maybe you altered the wrong file or there is another file where information survived. Please investigate.