I have a bash script that makes dump of DB then copies file from one server to another but it always asks for password before connection.
scp file.tar.gz root@xxx.xxx.xxx.194:/backup
Is there a way to pass password directly into script ?
feedback
|
|
Rather than using root create an account just for this job. Use public keys without a passphrase instead of passwords.
By using a special account for the backup on the destination system you are not exposing your root password. | |||
|
feedback
|
|
To transfer files without a password, create an Then you need to configure the target system's Bear in mind that compromised | |||
|
feedback
|
|
pscp allows you to pass the password to it directly - just use the -p arguement. Alternately, and this is a better idea, use ssh agent and set up key based logon - this is more secure. There's a howto on setting up ssh to use key based logon here You can use the yes command to send a yes to the program. | |||
|
feedback
|
|
The usual way to do this is to setup keys appropriately ahead of time. Passing a password on a command line or in a shell script is generally considered quite insecure, as (depending on the system), the password may be visible to anyone who does a 'ps' on the system. If you really can't setup keys, and you've arranged things on both ends such that you don't care if someone gets the password, then you could try passing it to the input of scp like this:
However, given that you've got the root account as your target, I'm gonna say this is a REALLY bad idea, because scp runs over-top of the ssh protocol, which means anyone who can scp files in there can usually log in using ssh with the same password. Instead, you should be setting up a set of private keys that allow the server doing the scp to push files to a particular directory on the target server. I'd also recommend NOT using the root account on the target server - instead, create a separate account that has minimum privileges, and is just used to receive these transfers. That minimizes your exposure on the target box in case of something going wrong. | |||||
feedback
|
|
It's better to set up ssh to used key-based authentication rather than trying to figure out how to send text to the login process with something like Take a look at: https://help.ubuntu.com/community/SSH/OpenSSH/Keys So, basically, run Copy the public key to the second server using You should now be able to run ssh from the first machine and log in without a password. For copying the files, scp or rsync are fine. It depends on what you're doing. rsync will use ssh by default, so will use the key-based authentication you just set up. | |||
|
feedback
|
|
You should not use password-less ssh-keys for security reasons. The tool To install it on a Ubuntu machine just run the following command.
Check out the manpage for keychain for more information on how to use it. | |||
|
feedback
|