Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: wq: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: wq: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
[root@samba caozx26]# cat rsa.sh#!/bin/expectsetip192.168.235.3
set pass 123456settimeout30
spawn ssh root@$ip:cat ~/.ssh/id_rsa.sh
expect{"yes/no"{ send "yes\r";exp_continue }"password"{ send "$pass\r"}}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3:cat ~/.ssh/id_rsa.sh
ssh: Could not resolve hostname192.168.235.3:cat: Name or service not known
spawn_id: spawn id exp6 not openwhile executing
"interact"(file "./rsa.sh" line 11)
记录
┌─────────────────────────────────────────────────────────────────── ───┐│ • MobaXterm Personal Edition v23.2 • ││ (SSH client, X server and network tools) ││ ││ ⮞ SSH session to code@192.168.235.10 ││ • Direct SSH : ✓ ││ • SSH compression : ✓ ││ • SSH-browser : ✓ ││ • X11-forwarding : ✓ (remote display is forwarded through SSH ) ││ ││ ⮞ For more info, ctrl+click on help or visit our website. │└─────────────────────────────────────────────────────────────────── ───┘Last login: Wed Aug 2021:35:45 2025 from 192.168.235.1
[code@samba ~]$ sudosu[sudo] code 的密码:
code 不在 sudoers 文件中。此事将被报告。
[code@samba ~]$ su - caozx26
密码:
上一次登录:日 8月 1710:55:56 CST 2025pts/4 上
[caozx26@samba ~]$ sudosu[sudo] caozx26 的密码:
[root@samba caozx26]# yum install expect -y
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
local1 |3.6 kB 00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 expect.x86_64.0.5.45-14.el7_1 将被 安装
--> 正在处理依赖关系 libtcl8.5.so()(64bit),它被软件包 expect-5.45-14.el7_1.x86_64 需要
--> 正在检查事务
---> 软件包 tcl.x86_64.1.8.5.13-8.el7 将被 安装
--> 解决依赖关系完成依赖关系解决==============================================================================Package 架构 版本 源 大小
==============================================================================
正在安装:expect x86_64 5.45-14.el7_1 local1 262 k
为依赖而安装:tcl x86_64 1:8.5.13-8.el7 local1 1.9 M事务概要
==============================================================================
安装 1 软件包 (+1 依赖软件包)总下载量:2.1 M
安装大小:4.9 M
Downloading packages:
------------------------------------------------------------------------------
总计 7.6 MB/s |2.1 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction正在安装 :1:tcl-8.5.13-8.el7.x86_64 1/2正在安装 : expect-5.45-14.el7_1.x86_64 2/2验证中 :1:tcl-8.5.13-8.el7.x86_64 1/2验证中 : expect-5.45-14.el7_1.x86_64 2/2已安装:expect.x86_64 0:5.45-14.el7_1作为依赖被安装:tcl.x86_64 1:8.5.13-8.el7完毕!
[root@samba caozx26]# which exxpect
/usr/bin/which: no exxpect in(/sbin:/bin:/usr/sbin:/usr/bin)[root@samba caozx26]# which expect
/bin/expect
[root@samba caozx26]# ssh root@192.168.235.3
The authenticity of host'192.168.235.3 (192.168.235.3)' can't be established.
ECDSA key fingerprint is SHA256:z4YsvU4MaDF8vJ2Z51wO5oAizA2QE2DNSqaae5BfBO0.
ECDSA key fingerprint is MD5:77:70:db:97:e6:0f:06:3f:23:40:9a:89:83:af:ac:ba.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
[root@samba caozx26]# ssh root@192.168.235.3
The authenticity of host '192.168.235.3 (192.168.235.3)' can't be established.
ECDSA key fingerprint is SHA256:z4YsvU4MaDF8vJ2Z51wO5oAizA2QE2DNSqaae5BfBO0.
ECDSA key fingerprint is MD5:77:70:db:97:e6:0f:06:3f:23:40:9a:89:83:af:ac:ba.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.235.3'(ECDSA) to the list of known hosts.root@192.168.235.3's password:
Last login: Fri Aug 29 20:59:12 2025 from 192.168.235.1
[root@nfs ~]# exit
登出
Connection to 192.168.235.3 closed.
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip=192.168.235.3
set pass=123456
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
[root@samba caozx26]# chmod +x rsa.sh
[root@samba caozx26]# ./rsa.sh
can't read"ip=192.168.235.3": no such variablewhile executing
"set ip=192.168.235.3"(file "./rsa.sh" line 2)[root@samba caozx26]# vim rsa.sh[root@samba caozx26]# cat rsa.sh#!/bin/expectsetip192.168.235.3
set pass 123456
spawn ssh root@$ipexpect{"yes/no"{ send "yes\r";exp_continue }"password"{ send "$pass\r"}}[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
[root@samba caozx26]# vim rsa.sh[root@samba caozx26]# cat rsa.sh#!/bin/expectsetip192.168.235.3
set pass 123456settimeout30
spawn ssh root@$ipexpect{"yes/no"{ send "yes\r";exp_continue }"password"{ send "$pass\r"}}[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
root@192.168.235.3's password: [root@samba caozx26]# ls
app km nntp.sh ntp.sh until.sh 模板 文档 桌面
find.sh l2 ntp1.sh rsa.sh utilc.sh 视频 下载
inotify.sh ll ntpdate.sh until1.sh 公共 图片 音乐
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
root@192.168.235.3's password:
Last login: Fri Aug 2921:03:23 2025 from 192.168.235.10
[root@nfs ~]# exit
登出
Connection to 192.168.235.3 closed.
[root@samba caozx26]# ls
app km nntp.sh ntp.sh until.sh 模板 文档 桌面
find.sh l2 ntp1.sh rsa.sh utilc.sh 视频 下载
inotify.sh ll ntpdate.sh until1.sh 公共 图片 音乐
[root@samba caozx26]# ls
app km nntp.sh ntp.sh until.sh 模板 文档 桌面
find.sh l2 ntp1.sh rsa.sh utilc.sh 视频 下载
inotify.sh ll ntpdate.sh until1.sh 公共 图片 音乐
[root@samba caozx26]# cat rsa.sh#!/bin/expectsetip192.168.235.3
set pass 123456settimeout30
spawn ssh root@$ipexpect{"yes/no"{ send "yes\r";exp_continue }"password"{ send "$pass\r"}}
interact
[root@samba caozx26]# cat rsa.sh#!/bin/expectsetip192.168.235.3
set pass 123456settimeout30
spawn ssh root@$ipexpect{"yes/no"{ send "yes\r";exp_continue }"password"{ send "$pass\r"}}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3
root@192.168.235.3's password:
Last login: Fri Aug 29 21:31:25 2025 from 192.168.235.10
[root@nfs ~]# exit
登出
Connection to 192.168.235.3 closed.
[root@samba caozx26]# exit
exit
[caozx26@samba ~]$ cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[caozx26@samba ~]$ cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[caozx26@samba ~]$ vim rsa.sh/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: a: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: wq: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: q: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
/bin/bash: wq: 未找到命令Shell 已返回127请按 ENTER 或其它命令继续
[caozx26@samba ~]$ ls
app km nntp.sh ntp.sh until.sh 模板 文档 桌面
find.sh l2 ntp1.sh rsa.sh utilc.sh 视频 下载
inotify.sh ll ntpdate.sh until1.sh 公共 图片 音乐
[caozx26@samba ~]$ cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[caozx26@samba ~]$ vim rsa.sh
[caozx26@samba ~]$ sudo su
[sudo] caozx26 的密码:
[root@samba caozx26]# ls
app km nntp.sh ntp.sh until.sh 模板 文档 桌面
find.sh l2 ntp1.sh rsa.sh utilc.sh 视频 下载
inotify.sh ll ntpdate.sh until1.sh 公共 图片 音乐
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip:cat ~/.ssh/id_rsa.shexpect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3:cat ~/.ssh/id_rsa.sh
ssh: Could not resolve hostname 192.168.235.3:cat: Name or service not known
spawn_id: spawn id exp6 not openwhile executing
"interact"(file "./rsa.sh" line 11)
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip:cat ~/.ssh/id_rsa.sh
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip "cat ~/.ssh/id_rsa.sh"
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3 cat ~/.ssh/id_rsa.sh
root@192.168.235.3's password:
cat: /root/.ssh/id_rsa.sh: 没有那个文件或目录
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3 cat ~/.ssh/id_rsa.sh
root@192.168.235.3's password:
cat: /root/.ssh/id_rsa.sh: 没有那个文件或目录
[root@samba caozx26]# ssh root@192.168.235.3
root@192.168.235.3's password:
Last login: Fri Aug 2921:44:22 2025 from 192.168.235.10
[root@nfs ~]# cd ~/.ssh[root@nfs .ssh]# ls
id_rsa id_rsa.pub known_hosts
[root@nfs .ssh]# exit
登出
Connection to 192.168.235.3 closed.
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3 cat ~/.ssh/id_rsa.sh
root@192.168.235.3's password:
cat: /root/.ssh/id_rsa.sh: 没有那个文件或目录
[root@samba caozx26]# vim rsa.sh
[root@samba caozx26]# cat rsa.sh
#!/bin/expect
set ip 192.168.235.3
set pass 123456
set timeout 30
spawn ssh root@$ip "cat ~/.ssh/id_rsa.pub"
expect {"yes/no" { send "yes\r";exp_continue }"password" { send "$pass\r" }}
interact
[root@samba caozx26]# ./rsa.sh
spawn ssh root@192.168.235.3 cat ~/.ssh/id_rsa.pub
root@192.168.235.3's password:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDO0uF9+65Vnab1xc+GXvH/YqTXXfohWcTdFPtkbCzKjRez0bDAiOU9uVesqfEfQbjqcQFcwqIdR4MTSX9F+hu6dZkaHuPhDaXG7JCIa4N+8jpWPtOaY+nD0QHgRVheORIgKZvMv2/kYF6e8ihxo7FIUsYb5qT6+uZRWTnJAAc0x+EJSXIlwCaUVe9Pqdn7UECmO7gAlYZAcYz20iGgymz94IUfQIQtPEp1pbPquywFCpGcnEiA+pCNFuKqSC7sjbBWawWUdOwtAxlesD/hWRmYyqUGCVVQ+HYeBZHD1DlqFHCx7PDcViFO5tNbzxpC0q+jAC1O7vK5ueYU4xpI3xa1 root@nfs.cn
[root@samba caozx26]#