LINUX913 shell:set ip [lindex $argv 0],\r,send_user,spawn ssh root@ip “cat “

问题

获取公钥

bash 复制代码
[code@samba ~]$ cat pub.sh
#!/bin/usr/expect
set ip "$1"
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:cat ~/.ssh/id_rsa.pub
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect
}
}
}

[code@samba ~]$ vim
bash 复制代码
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip "$1"
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:cat ~/.ssh/id_rsa.pub
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "/r"}
"passphrase):" { send "/r" }
"again:" { send "/r" }
}
}
}


[code@samba ~]$ ./pub.sh
can't read "1": no such variable
    while executing
"set ip "$1""
    (file "./pub.sh" line 2)
[code@samba ~]$ ./pub.sh 192.168.235.12
can't read "1": no such variable
    while executing
"set ip "$1""
    (file "./pub.sh" line 2)
bash 复制代码
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip "lindex args0"
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:"cat ~/.ssh/id_rsa.pub"
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "/r"}
"passphrase):" { send "/r" }
"again:" { send "/r" }
}
}
}


[code@samba ~]$ ./pub.sh
spawn ssh root@192.168.235.100:"cat ~/.ssh/id_rsa.pub"
ssh: Could not resolve hostname 192.168.235.100:"cat: Name or service not known
[code@samba ~]$
bash 复制代码
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip [lindex $argv 0]
set pass 123456
set timeout 20
spawn ssh root@192.168.235.100 "cat ~/.ssh/id_rsa.pub"
expect {
"yes/no" {send "yes\r";exp_continue}
"password:" { send "$pass\r" }
timeout {
send_user "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "\r"}
"passphrase):" { send "\r" }
"again:" { send "\r" }
}
send_user "id_rsa.pub has been created"
}
send_user "id_rsa.pub is existed"
}


[code@samba ~]$ ./pub.sh
spawn ssh root@192.168.235.100 cat ~/.ssh/id_rsa.pub
root@192.168.235.100's password: [code@samba ~]$

记录

bash 复制代码
    ┌─────────────────────────────────────────────────────────────────┐
    │                 • 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 th SSH)  │
    │                                                                 │
    │ ⮞ For more info, ctrl+click on help or visit our website.       │
    └─────────────────────────────────────────────────────────────────┘

Last login: Sun Aug 31 14:59:20 2025 from 192.168.235.1
[code@samba ~]$ vim pub.sh
[code@samba ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/code/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/code/.ssh/id_rsa.
Your public key has been saved in /home/code/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ZdIv0j5weH79BKpjSw8Xt8kU/KyWP/CRP+vo8NKhly4 code@samba.w
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|         .   .   |
|        . +   o  |
|         * .   + |
|        S = o + +|
|         B . X O |
|          *.* & +|
|         .oEo=.B.|
|         .ooB=.o*|
+----[SHA256]-----+
[code@samba ~]$ cat pub.sh
#!/bin/usr/expect
set ip "$1"
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:cat ~/.ssh/id_rsa.pub
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect
}
}
}

[code@samba ~]$ vim pub.sh
[code@samba ~]$ vim pub.sh
[code@samba ~]$ cat pub.sh
#!/bin/usr/expect
set ip "$1"
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:cat ~/.ssh/id_rsa.pub
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "/r"}
"phase):" { send "/r" }
"):" { send "/r" }
}
}
}


[code@samba ~]$ vim pub.sh
[code@samba ~]$ vim pub.sh
[code@samba ~]$ vim pub.sh
[code@samba ~]$ cat pub.sh
#!/bin/usr/expect
set ip "$1"
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:cat ~/.ssh/id_rsa.pub
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "/r"}
"passphrase):" { send "/r" }
"again:" { send "/r" }
}
}
}


[code@samba ~]$ chmod +x pub.sh
[code@samba ~]$ ./pub.sh
-bash: ./pub.sh: /bin/usr/expect: 坏的解释器: 没有那个文件或目录
[code@samba ~]$ vim pub.sh
[code@samba ~]$ which ecpect
/usr/bin/which: no ecpect in (/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/mysql/bin:/home/code/.local/bin:/home/code/bin)
[code@samba ~]$ which expect
/bin/expect
[code@samba ~]$ vim pub.sh
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip "$1"
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:cat ~/.ssh/id_rsa.pub
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "/r"}
"passphrase):" { send "/r" }
"again:" { send "/r" }
}
}
}


[code@samba ~]$ ./pub.sh
can't read "1": no such variable
    while executing
"set ip "$1""
    (file "./pub.sh" line 2)
[code@samba ~]$ ./pub.sh 192.168.235.12
can't read "1": no such variable
    while executing
"set ip "$1""
    (file "./pub.sh" line 2)
[code@samba ~]$ vim pub.sh
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip "lindex args0"
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:cat ~/.ssh/id_rsa.pub
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "/r"}
"passphrase):" { send "/r" }
"again:" { send "/r" }
}
}
}


[code@samba ~]$ ./pub.sh
spawn ssh root@192.168.235.100:cat ~/.ssh/id_rsa.pub
ssh: Could not resolve hostname 192.168.235.100:cat: Name or service not known
[code@samba ~]$ vim pub.sh
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip "lindex args0"
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:"cat ~/.ssh/id_rsa.pub"
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "/r"}
"passphrase):" { send "/r" }
"again:" { send "/r" }
}
}
}


[code@samba ~]$ ./pub.sh
spawn ssh root@192.168.235.100:"cat ~/.ssh/id_rsa.pub"
ssh: Could not resolve hostname 192.168.235.100:"cat: Name or service not known
[code@samba ~]$ ./pub.sh 192.168.235.45
spawn ssh root@192.168.235.100:"cat ~/.ssh/id_rsa.pub"
ssh: Could not resolve hostname 192.168.235.100:"cat: Name or service not known
[code@samba ~]$ vim pub.sh
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip lindex $argv 0
set password 123456
set timeout 20
spawn ssh root@192.168.235.100:"cat ~/.ssh/id_rsa.pub"
expect {
"yes/no" {send "yes/r";exp_continue}
"password:" { send "$pass/r" }
timeout {
echo "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "/r"}
"passphrase):" { send "/r" }
"again:" { send "/r" }
}
}
}


[code@samba ~]$ vim pub.sh
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip [lindex $argv 0]
set pass 123456
set timeout 20
spawn ssh root@192.168.235.100 "cat ~/.ssh/id_rsa.pub"
expect {
"yes/no" {send "yes\r";exp_continue}
"password:" { send "$pass\r" }
timeout {
send_user "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "\r"}
"passphrase):" { send "\r" }
"again:" { send "\r" }
}
}
}


[code@samba ~]$ ./pub.sh
spawn ssh root@192.168.235.100 cat ~/.ssh/id_rsa.pub
root@192.168.235.100's password: [code@samba ~]$ vim pub.sh
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip [lindex $argv 0]
set pass 123456
set timeout 20
spawn ssh root@192.168.235.100 "cat ~/.ssh/id_rsa.pub"
expect {
"yes/no" {send "yes\r";exp_continue}
"password:" { send "$pass\r" }
timeout {
send_user "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "\r"}
"passphrase):" { send "\r" }
"again:" { send "\r" }
}
send_user "id_rsa.pub has been created"
}
send_user "id_rsa.pub is existed"
}


[code@samba ~]$ ./pub.sh
spawn ssh root@192.168.235.100 cat ~/.ssh/id_rsa.pub
root@192.168.235.100's password: [code@samba ~]$
bash 复制代码
[code@samba ~]$ ./pub.sh
spawn ssh root@192.168.235.100 cat ~/.ssh/id_rsa.pub
root@192.168.235.100's password: [code@samba ~]$ vim pub.sh
[code@samba ~]$ cat pub.sh
#!/bin/expect
set ip [lindex $argv 0]
set pass 123456
set timeout 20
spawn ssh root@192.168.235.100 "cat ~/.ssh/id_rsa.pub"
expect {
"yes/no" {send "yes\r";exp_continue}
"password:" { send "$pass\r" }
timeout {
send_user "id _rsa.pub not exsits"
expect "#"
send "ssh-keygen"
expect {
"rsa_pub):" { send "\r"}
"passphrase):" { send "\r" }
"again:" { send "\r" }
}
send_user "id_rsa.pub has been created"
}
send_user "id_rsa.pub is existed"
}
expect eof

[code@samba ~]$ ./pub.sh
spawn ssh root@192.168.235.100 cat ~/.ssh/id_rsa.pub
root@192.168.235.100's password:
cat: /root/.ssh/id_rsa.pub: 没有那个文件或目录
[code@samba ~]$
相关推荐
zhangfeng11339 小时前
win7 R 4.4.0和RStudio1.25的版本兼容性以及系统区域设置有关 导致Plots绘图面板被禁用,但是单独页面显示
开发语言·人工智能·r语言·生物信息
言之。15 小时前
TCP 拥塞控制设计空间课程要点总结
网络·网络协议·tcp/ip
eqwaak015 小时前
Matplotlib 动画显示进阶:交互式控制、3D 动画与未来趋势
python·tcp/ip·3d·语言模型·matplotlib
zhangfeng113316 小时前
在 R 语言里,`$` 只有一个作用 按名字提取“列表型”对象里的单个元素 对象 $ 名字
开发语言·windows·r语言
跨境小新16 小时前
ChatGPT大模型训练指南:如何借助动态代理IP提高训练效率
网络协议·tcp/ip·chatgpt
高-老师17 小时前
R语言生物群落(生态)数据统计分析与绘图实践技术应用
开发语言·r语言·生物群落
不会c嘎嘎17 小时前
Linux -- 基于TCP服务器实现一个简单的电商网站
linux·服务器·tcp/ip
啟明起鸣20 小时前
【网络编程】从与 TCP 服务器的对比中探讨出 UDP 协议服务器的并发方案(C 语言)
服务器·c语言·开发语言·网络·tcp/ip·udp