Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm attempting to copy a public key to a remote server. I'm logged in locally as [localname] and the key resides locally at ~/.ssh/. I'm also ssh'd into [remote.com] as [remotename], and attempting to upload the key thusly:

scp [localname]@localhost:~/.ssh/id_rsa.pub [remotename]@[remote.com]:/home/[remotename]/.ssh/uploaded_key.pub

I see the welcome message for [remote.com], but then I'm asked:

[localuser]@localhost's password:

But [localuser]'s password (the one [localuser] uses to log in to the local machine) isn't accepted:

Permission denied, please try again.

Here's the verbose output:

Executing: /usr/bin/ssh '-v' '-x' '-oClearAllForwardings yes' '-n' '-l' '[localname]' 'localhost' 'scp -v' '~/.ssh/id_rsa.pub' '[remotename]@[remote.com]:/home/[remotename]/.ssh/uploaded_key.pub'
OpenSSH_5.3p1 Debian-3ubuntu7, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/[remotename]/.ssh/identity type -1
debug1: identity file /home/[remotename]/.ssh/id_rsa type -1
debug1: identity file /home/[remotename]/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debian-3ubuntu7
debug1: match: OpenSSH_5.3p1 Debian-3ubuntu7 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu7
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host 'localhost' is known and matches the RSA host key.
debug1: Found key in /home/[remotename]/.ssh/known_hosts:5
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received

  *****************************************
  ** This is [remote.com] server **
  **  Unauthorized access is PROHIBITED  **
  *****************************************

debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/[remotename]/.ssh/identity
debug1: Trying private key: /home/[remotename]/.ssh/id_rsa
debug1: Trying private key: /home/[remotename]/.ssh/id_dsa
debug1: Next authentication method: password
[localname]@localhost's password: 
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
[localname]@localhost's password:

Can anyone verify that this is the correct usage of scp, or offer troubleshooting tips?

Localhost: Terminal 2.1.2 on Mac OS X 10.6.8 | Remote: Ubuntu 10.04

share|improve this question

3 Answers 3

up vote 4 down vote accepted

That seems overly complicated. Try using the following from localhost:

scp ~/.ssh/id_rsa.pub [remotename]@[remote.com]:.ssh/uploaded_key.pub
share|improve this answer
    
+1. I'm confirming this answer as correct. You should not include the user/host of the local part in your scp command. –  bahamat Apr 19 '12 at 21:54
    
Success! Apparently my command was attempting to use [localuser] as the username to log in to [remote.com], but that's not a user on that server. –  meetar Apr 20 '12 at 12:57

Interesting question, I just tried the same thing and came across the same bug. I used -vvv switch to figure out what's going on under the hood and basically it ssh's to your localhost and executes scp -v ~/.ssh/id_rsa.pub remoteuser@remoteserver:~/

This should work fine, however, the command tries to read password from stdin but without a controlling tty, there's no password, hence the permission denied messages.

Here's a cut down version of debug, which explains my point:

debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
dpac@localhost's password: 
debug3: packet_send2: adding 64 (len 60 padlen 4 extra_pad 64)
debug2: we sent a password packet, wait for reply
debug1: Authentication succeeded (password).
.
.
.

debug1: Sending command: scp -v ~/.ssh/id_rsa.pub REMOTEUSER@REMOTESERVER:~/
debug2: channel 1: request exec confirm 1
debug2: callback done
debug2: channel 1: open confirm rwindow 0 rmax 32768
debug2: channel 1: rcvd adjust 2097152
debug2: channel_input_status_confirm: type 99 id 1
debug2: exec request accepted on channel 1
debug2: channel 1: read<=0 rfd 5 len 0
debug2: channel 1: read failed
debug2: channel 1: close_read
debug2: channel 1: input open -> drain
debug2: channel 1: ibuf empty
debug2: channel 1: send eof
debug2: channel 1: input drain -> closed
debug2: channel 1: rcvd ext data 92
Executing: program /usr/bin/ssh host REMOTESERVER, user REMOTEUSER, command scp -v -t -- ~/
debug2: channel 1: written 92 to efd 7
debug2: channel 1: rcvd ext data 57
.
.
.
.
.

debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/dpac/.ssh/id_rsa
debug1: Trying private key: /home/dpac/.ssh/id_dsa
debug2: channel 1: written 214 to efd 7
debug2: channel 1: rcvd ext data 100
debug2: channel 1: rcvd ext data 73
debug1: Trying private key: /home/dpac/.ssh/id_ecdsa
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug2: channel 1: written 173 to efd 7
debug2: channel 1: rcvd ext data 174
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug2: channel 1: written 174 to efd 7
debug2: channel 1: rcvd ext data 101
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
debug2: channel 1: written 101 to efd 7
debug2: channel 1: rcvd ext data 73
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug2: channel 1: written 73 to efd 7
debug2: channel 1: rcvd ext data 152
debug1: Authentications that can continue: publickey,password
debug1: No more authentication methods to try.
Permission denied (publickey,password).
share|improve this answer

I have found no scp version so far that does support using the "remote" specification for source AND target.

share|improve this answer
1  
It does work. I've done it using keys. Your private key has to be on the 'local' and 'remote source' hosts. Your public key has to be on the 'remote source' and 'remote destination' hosts. –  bahamat Apr 19 '12 at 21:57
1  
To add to bahamat's comment, you must not use a passphrase for your keys for it to work. –  Deepak Mittal Apr 20 '12 at 4:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.