-1

I want to transfer files from one server to another.

scp -r user@11.11.11.22:/home/filename.php user@server.com:/home/scripts

When I run this command I received an answer that I need to put password for the server.com. But I'm not using the password, I'm using a key. how I can insert the key instead of the pass?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
  • 1
    Is the key on the local machine? I think unless you use [`-3`](https://superuser.com/a/401245/432690), your local key doesn't matter. – Kamil Maciorowski Feb 18 '20 at 18:23
  • The issue is you are using a third machine — your local machine — to copy files from `11.11.11.22` to `server.com`. I am sure if you login directly to `11.11.11.22` you can then run this command fine: `scp -r /home/filename.php user@server.com:/home/scripts`. – Giacomo1968 Feb 18 '20 at 18:25
  • But I logged on via putty to the server from which I want to send the files – ririririri Feb 18 '20 at 18:26
  • @ririririri If you are logged directly into `11.11.11.22` then your command doesn’t need the [user]@[hostname] stuff. It can just be `scp -r /home/filename.php user@server.com:/home/scripts`. In fact, drop the `-r` — since you are just copying one file — and run it like this: `scp /home/filename.php user@server.com:/home/scripts`. – Giacomo1968 Feb 18 '20 at 18:28

1 Answers1

0

The issue might be that you are using a third machine — your local machine — to copy files from 11.11.11.22 to server.com. I am sure if you login directly to 11.11.11.22 you can then run this command fine:

 scp -r /home/filename.php user@server.com:/home/scripts

But if you are actually logged directly into 11.11.11.22 then your command doesn’t need the [user]@[hostname] stuff. It can just be:

scp -r /home/filename.php user@server.com:/home/scripts

In fact, drop the -r — since you are just copying one file — and run it like this:

scp /home/filename.php user@server.com:/home/scripts

Just be sure you use the -A option when SSHing into 11.11.11.22. As the SSH man page states:

“Enables forwarding of the authentication agent connection. This can also be specified on a per-host basis in a configuration file.”

Meaning your key from your local machine is passed along during the SSH session. So you initially login to 11.11.11.22 like this:

 ssh -A user@11.11.11.22

You can then cleanly login to server.com like this:

ssh user@server.com

Which then means this SCP command should work without prompting for a password:

scp -r /home/filename.php user@server.com:/home/scripts
Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
  • It still asks me to enter the password. Can it be that the server needs to give me permission to send files? – ririririri Feb 18 '20 at 18:31
  • @ririririri “Can it be that the server needs to give me permission to send files?” As long as you can login, you should be good. When you are logged into `11.11.11.22` what happens when you just run `ssh user@server.com` and login to that other server? – Giacomo1968 Feb 18 '20 at 18:33
  • when i type ssh user@server.com it again asks me for password, but i dont have password, im using key to login – ririririri Feb 18 '20 at 18:34
  • @ririririri So when you initially SSH into `11.11.11.22`, I recommend using `ssh -A user@11.11.11.22`. And then when you are logged in, do `ssh user@server.com` and you should be able to login. That `-A` “Enables forwarding of the authentication agent connection. This can also be specified on a per-host basis in a configuration file.” Meaning it passes your keys from your local host to that connection. Meaning — if you use `ssh -A` — that when you are logged into `11.11.11.22`, the SSH agent will be aware of your key and you can then cleanly do an `ssh user@server.com` and log yourself in. – Giacomo1968 Feb 18 '20 at 18:41
  • I did it, but still asks me for password. – ririririri Feb 18 '20 at 18:47
  • @ririririri Then there are aspects of this setup you are not explaining well. Please look at the output of `ssh -A -v user@11.11.11.22` as well as the output of `ssh -v user@server.com` to see if that verbose output gives you any clues. – Giacomo1968 Feb 18 '20 at 18:48
  • debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: KEYRING:persistent:1002) – ririririri Feb 18 '20 at 18:51
  • @ririririri If you genuinely want help, you need to provide these details and specifics to your question. The reality is you are missing a lot of details in your question. Without those details, nobody here can help you. – Giacomo1968 Feb 18 '20 at 20:15