Using a variable’s value as password for scp, ssh etc. instead of prompting for user input every time

Indeed, you’ll definitely want to look into setting up ssh keys, over saving a password in a bash script. If the key is passwordless, then no user input will be required to ssh/scp. You just set it up to use the key on both ends and voila, secured communication.

However, I’ll get downvoted to hell if I don’t say this. Many consider passwordless ssh keys to be a Bad Idea(TM). If anybody gets their hands on the keys, the have full access. This means that you are relying on other security measures such as file permissions to keep your password safe.

Also, look into ssh-agent. It allows you to set it up so that you have a password protected ssh-key, but you only need to type it in once and it will manage the password for the key for you and use it when necessary. On my linux box at home, I have ssh-agent set up to run in my .xinitrc file so that it prompts me once and then starts X. YMMV.

UPDATE:
With regards to your requirements, password protected public key authentication + ssh-agent still seems to fit. Only the developers privy to the SSH/FTP password could start up ssh-agent, type in the password and ssh-agent would manage the passwords for the public keys for the rest of the session, never requiring interaction again.

Of course, how it stores it is another matter entirely. IANASE, but for more information on security concerns of using ssh-agent, I found symantec’s article to be pretty informative: http://www.symantec.com/connect/articles/ssh-and-ssh-agent

“The ssh-agent creates a unix domain
socket, and then listens for
connections from /usr/bin/ssh on this
socket. It relies on simple unix
permissions to prevent access to this
socket, which means that any keys you
put into your agent are available to
anyone who can connect to this socket.
[ie. root]” …

“however, [..] they are only usable
while the agent is running — root
could use your agent to authenticate
to your accounts on other systems, but
it doesn’t provide direct access to
the keys themselves. This means that
the keys can’t be taken off the
machine and used from other locations
indefinitely.”

Hopefully you’re not in a situation where you’re trying to use an untrusted root‘s system.

Leave a Comment