问题原文
原帖链接 · Dan · CC BY-SA 3.0
I'm trying to create a shell script that, among other things, starts up ssh-agent and adds a private key to the agent. Example:
#!/bin/bash
# ...
ssh-agent $SHELL
ssh-add /path/to/key
# ...
The problem with this is ssh-agent apparently kicks off another instance of $SHELL (in my case, bash) and from the script's perspective it's executed everything and ssh-add and anything below it is never run.
How can I run ssh-agent from my shell script and keep it moving on down the list of commands?
已采纳解答
原帖链接 · Michael Suelmann · CC BY-SA 3.0
ssh-agent is supposed to start a session and when it finishes the user session is over. So any command after ssh-agent would perhaps be executed after logoff.
What you want is a session-script that contains your sessions commands like this:
#!/bin/bash
ssh-add /path/to/key
bash -i # or other session starter
Then start ssh-agent session-script.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
