如何在没有提示的情况下执行ssh

编程入门 行业动态 更新时间:2024-10-21 15:47:08
本文介绍了如何在没有提示的情况下执行ssh-keygen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在Centos7上使用shell脚本自动生成一对ssh密钥,而我已经尝试过

I want to automate generate a pair of ssh key using shell script on Centos7, and I have tried

yes "y" | ssh-keygen -t rsa echo "\n\n\n" | ssh-keygen... echo | ssh-keygen..

所有这些命令都不起作用,只需输入一个"enter",shell脚本就停止在"Enter passphrase(空无密码)"上, 我只想知道如何在外壳中连续模拟多个输入".

all of these command doesn't work, just input one 'enter' and the shell script stopped on "Enter passphrase (empty for no passphrase)", I just want to know how to simulate mutiple 'enter' in shell continuously.

非常感谢任何人的帮助!

Many thanks if anyone can help !

推荐答案

只需使用无效通行证,并使用-N标志:

ssh-keygen -t rsa -N ''

要覆盖密钥文件(在本示例中为id_rsa):

ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa 2>/dev/null <<< y >/dev/null

在ssh-keygen man 页面上:

-N new_passphrase provides the new passphrase. -q silence ssh-keygen. -f filename specifies the filename of the key file.

分步说明

$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/klashxx/.ssh/id_rsa):

1 )为避免输入密钥,请使用-f:

1) To avoid entering the key use -f:

$ ssh-keygen -t rsa -f ~/.ssh/id_rsa Generating public/private rsa key pair. /home/klashxx/.ssh/id_rsa already exists. Overwrite (y/n)?

2 )现在,我们需要自动回答覆盖问题的" y "(让我们使用 此处字符串 ) :

2) Now we need to answer "y" automatically to the overwrite question (let's use a here-string for that job):

$ ssh-keygen -t rsa -f ~/.ssh/id_rsa <<< y Generating public/private rsa key pair. /home/klashxx/.ssh/id_rsa already exists. Overwrite (y/n)? Enter passphrase (empty for no passphrase):

3 )最后,我们将使用-N标志输入无效通行证:

3) Finally we're going to use the -N flag to enter a void pass:

$ ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa <<< y Generating public/private rsa key pair. /home/klashxx/.ssh/id_rsa already exists. Overwrite (y/n)? Your identification has been saved in /home/klashxx/.ssh/id_rsa. Your public key has been saved in /home/klashxx/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Xo0t6caMB/8TSsigxfY28JIfqYjyqxRZrFrPncx5yiU klashxx@server The key's randomart image is: +---[RSA 2048]----+ | | | . | | o . | | + * = | | +. + BSo= o | |...o.+o+XO... | |.. .o.E==+B. . | |o . ...=.o... | |.+o. o .. | +----[SHA256]-----+

4 )多余的球,清理输出,只需检查返回码即可:

4) Extra ball, cleanup the output, just check the return code:

$ ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa 2>/dev/null <<< y >/dev/null $ echo $? 0

荣誉

@ lukasz-dynowski,@ redochka,@ mellow-yellow和该线程中的其他人.

@lukasz-dynowski, @redochka, @mellow-yellow and the rest of the folks in this thread.

更多推荐

如何在没有提示的情况下执行ssh

本文发布于:2023-11-08 20:34:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1570388.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   提示   如何在   ssh

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!