我在 .bashrc 文件中添加了以下行,以启动 ssh-agent(如果它未运行)。
if [ -z "$SSH_AUTH_SOCK" ];then eval `ssh-agent -s`;ssh-add ~/.ssh/my_private_key;fi
Run Code Online (Sandbox Code Playgroud)
但每次我再次登录时,ssh-agent 进程的数量都会增加如何避免这种情况。请查看以下日志并告诉我做错了什么。
[vm@localhost ~]$ ssh root@192.168.x.x
Last login: Wed Feb 15 06:32:07 2017 from x.x.x.x
[root@server ~]# pgrep ssh-agent | wc -l
2
[root@server ~]# exit
Shared connection to x.x.x.x closed.
[vm@localhost ~]$ ssh root@192.168.x.x
Last login: Wed Feb 15 06:32:20 2017 from x.x.x.x
[root@server ~]# pgrep ssh-agent | wc -l
3
[root@server ~]# exit
Shared connection to x.x.x.x closed.
[vm@localhost ~]$ ssh root@192.168.x.x
Last login: Wed …Run Code Online (Sandbox Code Playgroud)