配置ssh-agent免密码认证入门教程

ssh-agent是一个密钥管理器,运行ssh-agent以后,使用ssh-add将私钥交给ssh-agent保管,其他程序需要身份验证的时候可以将验证申请交给ssh-agent来完成整个认证过程。

生成密钥

$eval `ssh-agent -s` 注意这里是反引号
$ssh-add

为了使ssh-agent自动运行,将它写到profile中,在/etc/profile.d下新建ssh-agent.sh文件:

$sudo gedit /etc/profile.d/ssh-agent.sh 

shell密钥脚本程序

#!/bin/sh
if [ -f ~/.agent.env ]; then
 . ~/.agent.env >/dev/null
 if ! kill -0 $SSH_AGENT_PID >/dev/null 2>&1; then
 echo “Stale agent file found. Spawning new agent…”
 eval `ssh-agent |tee ~/.agent.env`
 ssh-add
 fi
else
 echo “Starting ssh-agent…”
 eval `ssh-agent |tee ~/.agent.env`
 ssh-add
fi

这样就不会生成太多的ssh-agent程序,而且支持GUI环境。

打开终端

Stale agent file found. Spawning new agent…
Agent pid 2543
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

添加了新的密钥。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注