首页 > 系统相关 >shell调用expect实现用户创建免密登录

shell调用expect实现用户创建免密登录

时间:2024-10-06 16:00:04浏览次数:1  
标签:免密 rsa send shell expect id ssh

这是一个用于(批量或者免交互)创建用户免密的shell脚本

通过shell的for循环和变量,实现批处理和免交互

#!/bin/bash
password="liwanliang"
expect -c "
        spawn ssh liwl@node084
        expect {
                \"*yes/no*\" { send \"yes\r\", exp_continue }
                \"*password:*\" { send \"${password}\r\" }
        }
        expect \"$ \"
        send \"ssh-keygen -t rsa -f ~/.ssh/id_rsa -P \'\'\r\"
        expect \"$ \"
        send \"cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys\r\"
        expect \"$ \"
        send \"chmod 600 ~/.ssh/authorized_keys\r\"
        expect \"$ \"
        send \"exit\r\"
"
echo "操作成功!"

上面的cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys可以换成ssh-copy-id -i ~/.ssh/id_rsa.pub xxx@localhost

标签:免密,rsa,send,shell,expect,id,ssh
From: https://www.cnblogs.com/liwanliangblog/p/18449141

相关文章

  • xshell配置使用快捷键翻译选种内容
    1.win10安装python我安装的是python3.122.编辑翻译脚本申请百度翻译api的key和appid注意安装相关依赖包:requestswin10toastimportrequestsimportrandomimportjsonfromhashlibimportmd5importsysimportpyperclipfromwin10toastimportToastNotifier#S......
  • Reflection Conditional expectation
    Homework21Duedate:October9,2024(Wednesday).Pleasesubmityouranswerby11:59pm.Therearetotalof6questions.Q1(Reflection):ReadthesolutiontoHW1.Areyourownanswersinlinewiththesolutions?Ifnot,listthequestionsyoumissed.Dis......
  • Windows Powershell and WSL terminal 路径
    在windowspowershell中访问C,D盘cdC:,cdD:,...:PSC:\Users\phil>cdC:PSC:\Users\phil>pwdPath----C:\Users\philPSC:\Users\phil>在windowspowershell中访问WSL:PSC:\Users\phil>cd\\wsl.localhost\Ubuntu\home\phil\在W......
  • CS3214 Customizable Shell
    CS3214FProject1-“CustomizableShell”DueDate: Seewebsiteforduedate(Latedaysmaybeused.)Thisprojectmustbedoneingroupsof2students.Self-selectedgroupsmusthaveregis-teredusingthegrouperapp(URL).Otherwise,apartnerwillbea......
  • shell脚本常用命令
    常用命令2.1查看脚本执行过程2.2查看脚本是否有语法错误2.3date命令2.3.1显示年、月、日date+%Y-%m-%d   #年(以四位数字格式打印年份)月日date+%y-%m-%d   #年(以两位数字格式打印年份)月日date+%T         #年(以四位数字格式打印年份)月日2.3.2......
  • Shell脚本基础知识-初步版
    本文是笔者研究生期间在阅读《Linux命令行与shell脚本编程大全》之后总结出来的一些重点知识的记录,在此重新整理输出。以便在给上个帖子涉及到的相关知识点进行一下讲解,帮助自己复习shell脚本的首行规范化应该是#!/bin/bash#functiondescription其中第一行必须如此,#后......
  • Rustup-init.exe安装后执行cargo run 报错:`link.exe` returned an unexpected error的
    版本:rustc1.81.0(eeb90cda12024-09-04)报错情况如下图:摸索了后,总结一下关键解决方法:从微软件官网:https://visualstudio.microsoft.com/zh-hans/downloads/找到选项“用于VisualStudio的工具”,在其子项中下载“VisualStudio2022生成工具”下载后安装时,在Visualstu......
  • shc加密shell脚本总结
    shc介绍shc是shell编译器(ShellCompiler)的缩写,它可以对shell脚本进行编译和加密。它能够将shell脚本编译为可执行的二进制文件,其中包含了脚本的功能和逻辑,而不暴露源代码。可以说shc就是一个加密shell脚本的工具。shc的官方网址为:http://www.datsi.fi.upm.es/~frosal/sources/......
  • shell编程五
    10.循环10.1循环概述循环类型说明for循环最常用的循环,2种格式while循环当型循环while可以加入条件,死循环,读取文件dountil循环直到循环极少用10.2for循环10.2.1最常用的for循环格式#最常用的一种for变量in候补清单(列表)do命令doneforn......
  • shell脚本——检索mysql数据库中得用户,如果没有就创建
     #!/bin/bash#author:goujinyangset-eUSER1=mysqlsiUSER2=dbqueryUSER3=dboperUSER4=yyzcUSERS=($USER1$USER2$USER3$USER4)USER_PASS=123123#MySQL用户名和密码MYSQL_USER="root"MYSQL_PASSWORD="Root#123"#MYSQL_HOST="local......