For checking some git repositories it is very uncomfortable to work with public-keys because you have to commit the key every time you want to push, pull or other communications with the git repository.
If you have a lot of git repositories for a project you have to change to the first directory, make a git pull, commit your password for the public key and go to the next directory. For a lot of directories it is very bad style.
This is were ssh-agent comes to the spot. I start the ssh-agent and commit my password for the public key once with ssh-add. After that you can work with all git repositories were you have the same public key committed. The idea of the ssh-agent is to start it once and then you have to put some environment variables into all your shell where you are working. That's not very nice for me so I wrote a zsh-function for that case. Here you can see the function:
1: function ssha { 2: if [ $# -ne 1 ]; then 3: echo "usage: $0 [start|stop]" 4: return 1 5: fi 6: case "$1" in 7: start) 8: if [ -n "$SSH_AGENT_PID" ]; then 9: echo "ssh-agent already running" 10: return 1 11: fi 12: /usr/bin/ssh-agent > /tmp/ssh-agent-pids 13: . /tmp/ssh-agent-pids > /dev/null 14: /usr/bin/ssh-add 15: ;; 16: stop) 17: if [ -z "$SSH_AGENT_PID" ]; then 18: echo "ssh-agent not running" 19: return 1 20: fi 21: /usr/bin/ssh-agent -k > /tmp/ssh-agent-pids 22: . /tmp/ssh-agent-pids > /dev/null 23: ;; 24: *) 25: echo "usage: $0 [start|stop]" 26: return 1 27: ;; 28: esac 29: }
You can start and stop the ssh-agent with the same function. If you are working with some git repositories you could start it with ssha start. Then you have to give your password for the public key and you can work in the same shell. After finishing some work with that git repositories you could stop the server with ssha stop.
Keine Kommentare:
Kommentar veröffentlichen