[root@localhost ~]# cat ssh.sh
#!/bin/bash
expect -c "
spawn ssh root@192.168.30.3
expect \"\(yes/no\)\" { send \"yes\r\" }
expect \"password:\" { send \"123456\r\" }
interact
"
[root@localhost ~]# bash ssh.sh
spawn ssh root@192.168.30.3
The authenticity of host '192.168.30.3 (192.168.30.3)' can't be established.
ECDSA key fingerprint is SHA256:396BF852ITFX9y8B/HTvPAeICxxYzk4Wc7o8nWgyIQ4.
ECDSA key fingerprint is MD5:75:63:23:ba:73:cc:5d:4d:e6:2a:6a:9b:c3:71:43:a7.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.30.3' (ECDSA) to the list of known hosts.
root@192.168.30.3's password:
Last login: Mon Jun 14 19:26:25 2021 from 192.168.30.254
[root@localhost ~]#