![]() In this case, you'd end up with that large code block above both in your ~/.bashrc or ~/.bash_aliases file, and in your script which needs to use the ssh-agent and add more keys to it. In case the script runs before you ever manually ssh in, though, you can add the entire large code block above to the script instead, so that it will prompt you to start the ssh-agent right there and let you type in your ssh keys right then. That simply tells your script to use the already-open ssh socket which you opened when you manually ssh-ed in. Then, to give any other script access to this agent, so that the script can use the keys, for instance, to push or pull to or from a GitHub code repo, add this to your script: export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock This will automatically start your ssh-agent and add default keys once per reboot whenever you ssh into your remote server. # see if any key files are already added to the ssh-agent, and if not, add themĮcho "No ssh keys have been added to your 'ssh-agent' since the last reboot. Ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sockĮxport SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock # for instance, will automatically start and manage the `ssh-agent` for you instead.Įcho "'ssh-agent' has not been started since the last reboot. Use the -e option (the password should be the first line of the filename): SSHPASS'4u2tryhack' sshpass -e ssh. # log into this machine, however, there is no need to do this, as Ubuntu's Gnome window manager, Here is the -f option when used in shell script: sshpass -f passfile ssh -o StrictHostKe圜heckingno. # into other machines or servers, such as to push code to GitHub over ssh. For example, run this script using script module for any host. Pseudo-ttys do not have a stderr channel and all stderr is sent to stdout. The ssh connection plugin will force pseudo-tty allocation via -tt when scripts are executed. # remote ssh server development machine that you generally ssh into, and from which you must ssh I am planning to execute a shell script on a remote server using Ansible playbook. # This is recommended to be added to your ~/.bash_aliases (preferred) or ~/.bashrc file on any ![]() ![]() In your server's ~/.bashrc or ~/.bash_aliases file, add this: # Auto-start the ssh agent and add necessary keys once per reboot. It is based on this answer here, but has my modifications. ![]() In case this is what you want, this works perfectly. This is a bit of a security risk as well, but is a tradeoff between convenience and security and is better than removing your ssh password entirely. Even better, you might want to share your ssh-agent socket with all processes so that if one process adds some keys, they are accessible to you and all other processes later. ssh command will break out of the while-loop, and that the script doesnt complete all the intended ssh commands. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |