我从cron作业调用一个脚本。 在脚本中,需要运行CVS命令从远程存储库进行更新。 要做到这一点,它需要SSHauthentication。
我把下面的代码放在脚本中
... ROOTPATH="/Users/qazwsx/project/" cd $ROOTPATH SSHAGENT="${ROOTPATH}ssh-agent.cf" if [ -f "$SSHAGENT" ]; then rm "$SSHAGENT" fi ssh-agent -s | head -n 2 > "$SSHAGENT" if [ -f "$SSHAGENT" ]; then echo "$SSHAGENT" source "$SSHAGENT" ssh-add #function killsshagent { # /bin/kill $SSH_AGENT_PID #} #trap killsshagent EXIT rm "$SSHAGENT" fi ...
但是当脚本运行时,会出现如下窗口:

我不能input任何东西到input字段。 所以SSHvalidation后的步骤没有成功运行,因为SSH访问没有build立。 我想知道我应该怎么做cron作业中的CVS更新。
你可以创build另一个密钥对,不需要密码:
$ ssh-keygen -t rsa -b 4096 -f〜/ .ssh / cvs_rsa.id
然后将〜/ .ssh / cvs_rsa.id.pub的内容添加到远程主机的authorized_keys中。 然后,您应该能够从脚本中“ssh -i〜/ .ssh / cvs_rsa.id user @ remotehost”。
请注意,在创build没有密码的密钥时,拥有私钥文件的任何人都可以像您一样login。 谨慎使用!
更新:从ssh-keygen(1)手册页:
ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment] [-f output_keyfile] -b bits Specifies the number of bits in the key to create. For RSA keys, the minimum size is 768 bits and the default is 2048 bits. Generally, 2048 bits is considered sufficient. DSA keys must be exactly 1024 bits as speci‐ fied by FIPS 186-2. For ECDSA keys, the -b flag determines the key length by selecting from one of three elliptic curve sizes: 256, 384 or 521 bits. Attempting to use bit lengths other than these three values for ECDSA keys will fail. -t type Specifies the type of key to create. The possible values are “rsa1” for protocol version 1 and “dsa”, “ecdsa” or “rsa” for protocol version 2.
所以,基本上这个命令说,做一个4096位的RSA密钥,并将其作为cvs_rsa.id存储在当前用户主目录的.ssh目录中。 〜/ .ssh /扩展到$ HOME / .ssh / $ $ HOME的任何值被设置。