SCP command script with password in same line??
I have written a script which will send the backup "adon.gz" file every evening at 6 from Node1 to Node2.
What I did is putting : Code:
scp adon.gz root@10.14.234.321:/root Is there any method to response for the password therein if the script ask for?Pls Help |
Rather than the password, which is in the clear, the *usual* way of doing an scp without typing in a password is by setting up entries in the users' 'authorized_keys' files.
Assuming you have UserA and UserB who are on different machines, each of these users will have private and public key information in $HOME/.ssh/ - typically the user's info is 'id_rsa.pub' and 'id_rsa'. public key information from the remote user(s) would be in the file 'authorized_keys'. If those files do not exist, then they simply haven't been created yet. I am assuming here that the sysadmin has put fairly lax restrictions on the use of ssh and that a user can connect to an arbitrary remote using their own key files *and* can even specify their own list of 'known_hosts'. 1. Creating the id_rsa key files: UserA and UserB each need to generate their respective key files: ssh-keygen -b 2048 -t rsa -N "" -C "User A's Secret Recipe" The '-N ""' means "no passphrase" - if you put on a passphrase that means you need to enter a passphrase to connect - which you don't want. The "-C" is a comment - you can leave it blank or put in something to remind you what that key is for. 2. Setting up the known_hosts file: ComputerA (which hosts UserA) will have a host key in /etc/ssh/ssh_host_rsa_key.pub you must add that file's contents to the $HOME/.ssh/known_hosts file on ComputerB. Or if admin restrictions prevent it, the admin must add the contents of that file to /etc/ssh/ssh_known_hosts. Same for ComputerB - it needs its public host key info in the remote's known_hosts or ssh_known_hosts file. 3. Setting up the authorized_keys file: UserA has a public key file .ssh/id_rsa.pub - the contents of that file must be added to UserB's .ssh/authorized_keys file. At this point UserA can use scp/ssh/sftp (and other tools like rsync) to issue commands to ComputerB via UserB's account. UserB also has a public key file - putting that information into UserA's authorized_keys file will now allow UserB to do horrible things to ComputerA using UserA's credentials. |
All times are GMT -5. The time now is 05:35 AM. |