mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-02-25 00:50:15 +08:00
校对完毕
校对完毕
This commit is contained in:
parent
edcd5a3e3f
commit
c1093270f0
@ -1,32 +1,32 @@
|
||||
sshpass:一个很棒的无交互SSH登录工具 - 不要在生产服务器上使用
|
||||
sshpass:一个很棒的无交互 SSH 登录工具 - 安全原因,不要在生产服务器上使用
|
||||
============================================================
|
||||
|
||||
在大多数情况下,Linux系统管理员使用SSH通过密码或[无密码SSH登录][1]或基于密钥的SSH身份验证登录到远程Linux服务器。
|
||||
在大多数情况下,Linux 系统管理员使用 SSH,通过密码或[无密码 SSH 登录][1]或基于密钥的 SSH 身份验证登录到远程 Linux 服务器。
|
||||
|
||||
如果你想自动在SSH中提供密码和用户名怎么办?这是可以用sshpass了。
|
||||
如果你想自动在 SSH 中提供**密码**和**用户名**怎么办?这是可以用 **sshpass** 了。
|
||||
|
||||
sshpass是一个简单、轻量级的命令行工具,使我们能够向命令提示符本身提供密码(非交互式密码验证),以便可以通过[cron调度器][2]执行自动化的shell脚本进行备份。
|
||||
sshpass 是一个简单、轻量级的命令行工具,通过它我们能够向命令提示符本身提供密码(非交互式密码验证),这样就可以通过 [cron 调度器][2]执行自动化的 shell 脚本进行备份。
|
||||
|
||||
ssh直接使用TTY访问,以确保密码是用户键盘输入的。 sshpass在专门的tty中运行ssh,以误导它相信它是从用户接收到的密码。
|
||||
ssh 直接使用 TTY 访问,以确保密码是用户键盘输入的。 sshpass 在专门的 tty 中运行 ssh,以误导它相信它是从用户接收到的密码。
|
||||
|
||||
重要:使用sshpass被认为是最不安全的,因为它通过简单的“ps”命令就可在命令行上显示所有系统用户的密码。我强烈建议使用[SSH无密码身份验证][3]。
|
||||
重要:使用 **sshpass** 被认为是最不安全的,因为在命令行中通过简单的 “**ps**” 命令就可将密码显示给所有系统用户。我强烈建议使用 [SSH 无密码身份验证][3]。
|
||||
|
||||
### 在Linux中安装sshpass
|
||||
### 在 Linux 中安装 sshpass
|
||||
|
||||
在基于RedHat/CentOS的系统中,首先需要[启用Epel仓库][4]并使用[yum命令安装][5]它。
|
||||
在基于 **RedHat/CentOS** 的系统中,首先需要[启用 Epel 仓库][4]并使用[ yum 命令][5]安装它。
|
||||
|
||||
```
|
||||
# yum install sshpass
|
||||
# dnf install sshpass [On Fedora 22+ versions]
|
||||
```
|
||||
|
||||
在Debian/Ubuntu和它的衍生版中,你可以使用[apt-get命令][6]来安装。
|
||||
在 Debian/Ubuntu 和它的衍生版中,你可以使用 [apt-get 命令][6]来安装。
|
||||
|
||||
```
|
||||
$ sudo apt-get install sshpass
|
||||
```
|
||||
|
||||
另外你也可以从最新的源码安装sshpass,首先下载源码并从tar文件中解压出内容:
|
||||
另外,你也可以从最新的源码安装 sshpass,首先下载源码并从 tar 文件中解压出内容:
|
||||
|
||||
```
|
||||
$ wget http://sourceforge.net/projects/sshpass/files/latest/download -O sshpass.tar.gz
|
||||
@ -36,14 +36,14 @@ $ ./configure
|
||||
# sudo make install
|
||||
```
|
||||
|
||||
### 如何在Linux中使用sshpass
|
||||
### 如何在 Linux 中使用 sshpass
|
||||
|
||||
sshpass与ssh一起使用,可以使用下面的命令查看sshpass的使用使用选项的完整描述:
|
||||
**sshpass** 与 **ssh** 一起使用,使用下面的命令可以查看 sshpass 的使用选项的完整描述:
|
||||
|
||||
```
|
||||
$ sshpass -h
|
||||
```
|
||||
sshpass Help
|
||||
下面为显示的 sshpass 帮助内容:
|
||||
```
|
||||
Usage: sshpass [-f|-d|-p|-e] [-hV] command parameters
|
||||
-f filename Take password to use from file
|
||||
@ -56,23 +56,23 @@ With no parameters - password will be taken from stdin
|
||||
At most one of -f, -d, -p or -e should be used
|
||||
```
|
||||
|
||||
正如我之前提到的,sshpass在用于脚本时才更可靠及更有用,考虑下面的示例命令。
|
||||
正如我之前提到的,**sshpass** 在用于脚本时才更可靠及更有用,考虑下面的示例命令。
|
||||
|
||||
使用用户名和密码登录到远程Linux ssh服务器(10.42.0.1),并如图所示[检查文件系统磁盘使用情况] [7]。
|
||||
使用用户名和密码登录到远程 Linux ssh 服务器(10.42.0.1),并[检查文件系统磁盘使用情况][7],如图所示。
|
||||
|
||||
```
|
||||
$ sshpass -p 'my_pass_here' ssh aaronkilik@10.42.0.1 'df -h'
|
||||
```
|
||||
|
||||
重要提示:此处,密码在命令行中提供,实际上不安全,不建议使用此选项。
|
||||
**重要提示**:此处,在命令行中提供了密码,这是不安全的,不建议使用此选项。
|
||||
|
||||
[
|
||||

|
||||
][8]
|
||||
|
||||
sshpass – 使用SSH远程登录Linux
|
||||
*sshpass – 使用 SSH 远程登录 Linux*
|
||||
|
||||
但是,为了防止在屏幕上显示密码,可以使用`-e`标志,并输入密码作为SSHPASS环境变量的值,如下所示:
|
||||
但是,为了防止在屏幕上显示密码,可以使用 `-e` 标志,并将密码作为 SSHPASS 环境变量的值输入,如下所示:
|
||||
|
||||
```
|
||||
$ export SSHPASS='my_pass_here'
|
||||
@ -83,11 +83,11 @@ $ sshpass -e ssh aaronkilik@10.42.0.1 'df -h'
|
||||

|
||||
][9]
|
||||
|
||||
sshpass – 在终端中隐藏密码
|
||||
*sshpass – 在终端中隐藏密码*
|
||||
|
||||
注意:在上面的示例中,SSHPASS环境变量仅用于临时目的,并将在重新启动后删除。
|
||||
**注意:**在上面的示例中,**SSHPASS** 环境变量仅用于临时目的,并将在重新启动后删除。
|
||||
|
||||
要永久设置SSHPASS环境变量,打开/etc/profile文件,并在文件开头输入export语句:
|
||||
要永久设置 **SSHPASS** 环境变量,打开 /etc/profile 文件,并在文件开头输入 export 语句:
|
||||
|
||||
```
|
||||
export SSHPASS='my_pass_here'
|
||||
@ -99,7 +99,7 @@ export SSHPASS='my_pass_here'
|
||||
$ source /etc/profile
|
||||
```
|
||||
|
||||
另一方面,你也可以使用`-f'标志,并把密码放在一个文件中。 这样,您可以从文件中读取密码,如下所示:
|
||||
另外,也可以使用`-f`标志,并把密码放在一个文件中。 这样,您可以从文件中读取密码,如下所示:
|
||||
|
||||
```
|
||||
$ sshpass -f password_filename ssh aaronkilik@10.42.0.1 'df -h'
|
||||
@ -108,9 +108,9 @@ $ sshpass -f password_filename ssh aaronkilik@10.42.0.1 'df -h'
|
||||

|
||||
][10]
|
||||
|
||||
sshpass – 在登录时提供密码文件
|
||||
*sshpass – 在登录时提供密码文件*
|
||||
|
||||
你也可以使用sshpass[使用scp传输文件][11]或者[使用rsync备份/同步文件][12],如下所示:
|
||||
你也可以使用 sshpass [通过 scp 传输文件][11]或者[ rsync 备份/同步文件][12],如下所示:
|
||||
|
||||
```
|
||||
------- Transfer Files Using SCP -------
|
||||
@ -119,19 +119,19 @@ $ scp -r /var/www/html/example.com --rsh="sshpass -p 'my_pass_here' ssh -l aaron
|
||||
$ rsync --rsh="sshpass -p 'my_pass_here' ssh -l aaronkilik" 10.42.0.1:/data/backup/ /backup/
|
||||
```
|
||||
|
||||
更多的用法,我建议你阅读一下sshpass的man页面,输入:
|
||||
更多的用法,建议阅读 **sshpass** 的 man 页面,输入:
|
||||
|
||||
```
|
||||
$ man sshpass
|
||||
```
|
||||
|
||||
在本文中,我们解释了sshpass是一个启用非交互式密码验证的简单工具。 虽然这个工具可能是有帮助的,但是强烈建议使用更安全的ssh公钥认证机制。
|
||||
在本文中,我们解释了 sshpass 是一个启用非交互式密码验证的简单工具。 虽然这个工具可能是有帮助的,但还是强烈建议使用更安全的 ssh 公钥认证机制。
|
||||
|
||||
请在下面的评论栏写下任何问题或评论,以便可以进一步讨论。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
作者简介:Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.
|
||||
作者简介:Aaron Kili 是一位 Linux 和 F.O.S.S 爱好者,未来的 Linux 系统管理员,web 开发人员, 还是 TecMint 原创作者,热爱电脑工作,并乐于分享知识。
|
||||
|
||||
-----------
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user