bash 脚本 ssh 自动登录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17388760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:48:45  来源:igfitidea点击:

bash script ssh auto login

bashsshautologin

提问by user1425394

Hello I am trying to make a script that when I run will connect and login to my ssh server. However I'm not sure how to stop it asking for my password, I want to somehow incorporate my password into my script so I dont have to type it manually. So the end product is I just run script and its connected to my server.

您好,我正在尝试制作一个脚本,当我运行时将连接并登录到我的 ssh 服务器。但是我不确定如何阻止它询问我的密码,我想以某种方式将我的密码合并到我的脚本中,这样我就不必手动输入它了。所以最终产品是我只运行脚本并将其连接到我的服务器。

At the moment I'm just using

目前我只是在使用

#!/bin/bash
ssh [email protected] -p 2222

#!/bin/bash
ssh [email protected] -p 2222

Was wonder what I might add so I wouldn't have to type password each time?
I was looked extensively for an answer but so far I my search has been fruitless.
I would appreciate any help maybe a suggestion on a bash command I could look up and read about.

想知道我可以添加什么,这样我就不必每次都输入密码了吗?
我广泛地寻找答案,但到目前为止我的搜索没有结果。
我会很感激任何帮助,也许是关于我可以查找和阅读的 bash 命令的建议。

回答by Martin Mandl

Create a public key and use it for authentication, e.g.:

创建一个公钥并将其用于身份验证,例如:

http://www.howtoforge.com/set-up-ssh-with-public-key-authentication-debian-etch

http://www.howtoforge.com/set-up-ssh-with-public-key-authentication-debian-etch

回答by Leigh

Use public key authentication, and probably run a ssh config file as well.

使用公钥认证,也可能运行一个 ssh 配置文件。

Simple summary on config files: http://nerderati.com/2011/03/simplify-your-life-with-an-ssh-config-file/

配置文件的简单摘要:http: //nerderati.com/2011/03/simplify-your-life-with-an-ssh-config-file/