LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 875|回复: 4

请教:避免ssh提示输入密码的办法?

[复制链接]
发表于 2004-12-19 15:38:40 | 显示全部楼层 |阅读模式
请问有什么办法可以将 password 直接加到脚本中,这样我使用 ssh 的时候不会被提示要输入密码?

我在 ssh 的 man 手册中又没有看到有这样的参数选项。

先谢谢了。
发表于 2004-12-19 16:09:39 | 显示全部楼层
请参考下面:
ssh implements the RSA authentication protocol automatically.  The user
     creates his/her RSA key pair by running ssh-keygen(1).  This stores the
     private key in $HOME/.ssh/identity and the public key in
     $HOME/.ssh/identity.pub in the user<A1><AF>s home directory.  The user shou
ld
     then copy the identity.pub to $HOME/.ssh/authorized_keys in his/her home
     directory on the remote machine (the authorized_keys file corresponds to
     the conventional $HOME/.rhosts file, and has one key per line, though
     the lines can be very long).  After this, the user can log in without
     giving the password.
 楼主| 发表于 2004-12-20 00:10:30 | 显示全部楼层
是的,这种方法有效。谢谢版主。
但我看资料说,可以使用 ssh-agent + ssh-add 的方法来提供脚本的便利,我尝试使用 ssh-add,但出现:
Could not open a connection to your authentication agent.
即使我已经允许 ssh-agent,还是如此。

这是为什么?
发表于 2004-12-20 01:57:16 | 显示全部楼层
Post by Chowroc
是的,这种方法有效。谢谢版主。
但我看资料说,可以使用 ssh-agent + ssh-add 的方法来提供脚本的便利,我尝试使用 ssh-add,但出现:
Could not open a connection to your authentication agent.
即使我已经允许 ssh-agent,还是如此。

这是为什么?


  1. [[ "$(id -un)" = "yongjian" ]] && ssh-agent | head -2 > ~/.ssh/ssh-agent.config && . ~/.ssh/ssh-agent.config && ssh-add
复制代码


将上面这个加到你的/etc/profile中. 把我的登录名改成你自己的.

直接不行是因为你没有指定ssh_agent的socket.而且ssh_agent client每隔几秒就refresh了. 直接ssh-add是定位不到的.
 楼主| 发表于 2004-12-20 19:00:23 | 显示全部楼层
现在我基本上弄明白了:如果单纯使用authorized_keys的方法,那么除非在ssh-keygen的时候不输入passphase的密码,否则无法在脚本中避免口令输入提示。而使用ssh-agent,则在keygen时使用了passphase密码,可以交给ssh-agent来管理,当然还是要把公共密钥复制到服务器的authorized_keys中。

要使用ssh-add,要先允许ssh-agent,并启动一个shell,如:
$ ssh-agent /bin/bash
$ ssh-add
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表