Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SSH

Status
Not open for further replies.

ilovelinux2006

Programmer
Jun 6, 2006
32
US
Hi Everyone,
In a bash script, I am trying to connect to another computer to transfer a file. How should I go about doing this? Through SSH? or SCP? I think the scp command is somethign like this:
scp user@server.com:/directory /directorywhereyouwantthefile -p password

What am I doing wrong? Thanks! Im going to have the bash file run in crontab, so I'd like the password to just automatically be set.
 
Hi

First, the [tt]scp[/tt] command does not have -p option and you can not specifiy password as parameter. If you do not want to be prompted for password, you must use key based identification.

Second, if the source is a directory, you must specify a -r option too.

Feherke.
 
how about secure ftp?

-------------------------
The trouble with doing something right the first time is that nobody appreciates how difficult it was - Steven Wright
 
I've done this. First you have to use the ssh-keygen utility on one of the server to generate a public and private key.

This is all user specific. I tend to keep my usernames the same across each server to keep it simple.

Then you just scp it. scp works nicely with ssh keys.

 
Thanks ostek, johnherman, and feherke

I created a key
ssh-keygen -d -C testing@server.website.com
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa): /root/.ssh/id_dsa
/root/.ssh/id_dsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
93:ad:22:89:07:f2:83:c7:a3:9f:62:31:c0:b8:12:86 testing@server.website.com

Ok, now that I have the key, whats my next step? To export that key to the remote server so I can use the scp command? And if so, what directory should I export that key to on the remote server? Thanks!!
 
Do you really need to use root to do this? It's not the best idea unless you have to.

Now you just need to copy the id_dsa.pub to ~/.ssh/authorized_keys in the home directory of the user on the destination server.

Annihilannic.
 
Ok Guys, Im using Gentoo on the main server and on the destination server I have Fedora 5. I created the id_dsa.pub on the Gentoo server. It reads something like this:

ssh-dss AAAAB3NzaC1kc3MAAACBAJzy8XoNhIOOJRgpNfQHywLeMUQXq7+YaY+0rWdZ8Wy0/ = username@theserver.com

Then I copied that exactly into the Fedora 5 server (destination server) in the file authorized_keys into the directory /home/username/.ssh/

I had to mkdir .ssh for username, but its still prompting me for a password when I do:
scp file username@theserver.com:/home/username/file

Any ideas? Thanks!
 
Make sure the mode of the .ssh dir that you made is 600, or else the sshd on that server will ignore its contents.

Annihilannic.
 
When I created the user "username" I gave it a password. Does that password have to be in the paraphrase? Becasue When I created the id_dsa.pub on the gentoo server, I left the paraphrase blank. Does that matter? The directory is 700 on the .ssh directory on the Fedora 5 server. Thanks Annihilannic!
 
You need to use a blank passphrase for non-interactive logins. It has no relationship with the users' password.

Next thing to try is run sshd in debug mode on the destination server, i.e. sshd -d -p1234. Then from the source server do a test command like ssh -p1234 remotehost date and carefully decipher the sshd debugging output to see why it's rejecting the keys and falling back to keyboard-interactive.

Annihilannic.
 
When I try to do sshd -d -p1234 it says:
sshd -d -p1234
sshd re-exec requires execution with an absolute path
 
If I put
scp minute5.txt username@servername.com

That goes through, w/o a password. Where does it put the minute5.txt file?
 
Hi

ilovelinux2006 said:
scp minute5.txt username@servername.com
I do not belive that works.
man scp said:
scp [-pqrvBC46] [-F ssh_config] [-S program] [-P port] [-c cipher]
[-i identity_file] [-o ssh_option] [[user@]host1:]file1 [...]
[[user@]host2:]file2
Which means the colon ( : ) is mandatory.

Ifqou wrote it as [highlight lightblue]scp minute5.txt username@servername.com[red]:[/red][/highlight], then in the home of username.

Feherke.
 
That will have created a file on the local system called username@servername.com. When no hostname is specified scp just behaves like cp.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top