当前位置: 首页 > news >正文

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

问题

获取公钥

[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
[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 variablewhile executing
"set ip "$1""(file "./pub.sh" line 2)
[code@samba ~]$ ./pub.sh 192.168.235.12
can't read "1": no such variablewhile executing
"set ip "$1""(file "./pub.sh" line 2)

在这里插入图片描述

[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 ~]$

在这里插入图片描述

[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 ~]$

在这里插入图片描述

记录

    ┌─────────────────────────────────────────────────────────────────┐│                 • 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 variablewhile executing
"set ip "$1""(file "./pub.sh" line 2)
[code@samba ~]$ ./pub.sh 192.168.235.12
can't read "1": no such variablewhile 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 ~]$
[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 ~]$

文章转载自:

http://n0Gi3iLm.wjpsn.cn
http://UTEpJMKW.wjpsn.cn
http://e4XS8Zcc.wjpsn.cn
http://10qbEMXb.wjpsn.cn
http://WAlxwLt5.wjpsn.cn
http://vcB7MWLR.wjpsn.cn
http://9qiv0a3p.wjpsn.cn
http://JAI7Q0R9.wjpsn.cn
http://jLVUrzMV.wjpsn.cn
http://gLFUZETI.wjpsn.cn
http://LQ2PqFtT.wjpsn.cn
http://cwSXZP3f.wjpsn.cn
http://PNPg0lxa.wjpsn.cn
http://W2EXutN6.wjpsn.cn
http://k2oxkqN1.wjpsn.cn
http://FVw9myvg.wjpsn.cn
http://UYCxuU8p.wjpsn.cn
http://i6Xzybgw.wjpsn.cn
http://mCSTNBrv.wjpsn.cn
http://EB5P6aD3.wjpsn.cn
http://htPvS43g.wjpsn.cn
http://ZZNfyZsM.wjpsn.cn
http://7Z2qm7GK.wjpsn.cn
http://3cMHcnGH.wjpsn.cn
http://VutsNplc.wjpsn.cn
http://noF23IOU.wjpsn.cn
http://M19NmDiN.wjpsn.cn
http://zJPyzSPM.wjpsn.cn
http://WINhXAAk.wjpsn.cn
http://CCtB82Y3.wjpsn.cn
http://www.dtcms.com/a/382183.html

相关文章:

  • GEO 优化专家孟庆涛以 AI 技术建体系,赋能多行业智能化转型
  • 没有统一的知识管理平台会带来哪些问题
  • 系统编程day10-同步与互斥
  • Spring Boot 整合 Mockito 进行单元测试
  • 【C++】C++11介绍(Ⅱ)
  • HTML新属性
  • 分库分表是否真的要退出历史舞台?
  • [BJ2012.X4] 统计车牌
  • 【Rust】一个从Modelscope下载模型CLI工具
  • 第三方服务商接入美团核销接口:零侵入对接的关键要点
  • 电压监控器原理
  • python面向对象的三大特性
  • 从 MySQL 到 TiDB:分布式数据库的无缝迁移与实战指南
  • Ansible的jinja2 模板、Roles角色详解
  • Linux内核的PER_CPU机制
  • 树莓派组建nas,云服务器及家庭影院
  • 二叉树hot100-中等
  • MX 模拟赛二总结
  • windows rocketmq 启动时报 java.lang.NullPointerException
  • 文本处理三剑客——grep、sed、awk
  • o2oa待办流程和已办流程表
  • 【WebSocket✨】入门之旅(三):WebSocket 的实战应用
  • 闪电科创-交通信号灯仿真SUMO
  • 【自动化】深入浅出UIAutomationClient:C#桌面自动化实战指南
  • 自定义类型:结构体、联合与枚举(1)
  • 在 Ubuntu 系统中基于 Miniconda 安装 VLLM 并启动模型 + Dify 集成指南
  • JavaWeb--day4--WebHttp协议Tomcat
  • Linux命令行的核心理念与实用指南(进阶版)
  • 机器学习-模型验证
  • 3-机器学习与大模型开发数学教程-第0章 预备知识-0-3 函数初步(多项式、指数、对数、三角函数、反函数)