问题原文
原帖链接 · Click Upvote · CC BY-SA 3.0
I'm trying to have the following commands be auto-executed when I login to my server via ssh:
ssh-agent /bin/bash
ssh-add ~/.ssh/id_rsa
My ssh key has a passphrase and I'm fine with entering it once per login.
I tried putting this in my .bashrc file, however I believe that ssh-agent starts a new bash session. When I try to login after having this in my .bashrc, it gets stuck, and I have to type 'exit' to then see the 'enter passphrace to unlock key' prompt
Any other suggestions?
Server is running Ubuntu LTS
已采纳解答
原帖链接 · Tobi Oetiker · CC BY-SA 4.0
You can try adding this:
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
This way the ssh-agent does not start a new shell, it just launches itself in the background and spits out the shell commands to set the appropriate environment variables.
As said in the comment, maybe you do not want to run the agent at all on the remote host, but rather on the box you are working from, and use
ssh -A remote-host
to forward the services of your local ssh agent to the remote-host.
For security reasons you should only use agent forwarding with hosts run by trustworthy people, but it is better than running a complete agent remotely any time.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
