4

I am able to ssh into my Amazon EC2 instance with ssh -i node.pem ubuntu@35.164.71.227

I am trying to copy over a folder called gametest from my laptop to the instance in a folder called gametest. I keep getting permission denied. I tried the command scp -v -r -i node.pem /Users/path/to/file/gametest ubuntu@35.164.71.227:/gametest. What is going wrong?

Here is the verbose output (I changed my username to USER for privacy).

Executing: program /usr/bin/ssh host 35.164.71.227, user ubuntu, command scp -v -r -t /gametest
OpenSSH_7.3p1, LibreSSL 2.4.1
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 20: Applying options for *
debug1: Connecting to 35.164.71.227 [35.164.71.227] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file node.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file node.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 35.164.71.227:22 as 'ubuntu'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:N7OMBCEHZm9trGWevCHV02WAffY49Bt6ET9qQOqdvqM
debug1: Host '35.164.71.227' is known and matches the ECDSA host key.
debug1: Found key in /Users/USER/.ssh/known_hosts:11
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: node.pem
debug1: Authentication succeeded (publickey).
Authenticated to 35.164.71.227 ([35.164.71.227]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8
debug1: Sending command: scp -v -r -t /gametest
Entering directory: D0755 0 gametest
Sink: D0755 0 gametest
scp: /gametest: Permission denied
USER-mac01:downloads USER$ debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
Transferred: sent 2516, received 2592 bytes, in 0.2 seconds
Bytes per second: sent 10657.0, received 10979.0
debug1: Exit status 1
  • What happens with scp -v -r -i node.pem /Users/path/to/file/gametest ubuntu@35.164.71.227:? Does the remote ubuntu user has the proper rights to create directories and files? – marcanuy Dec 30 '16 at 23:56
  • Hm, that worked out for me. Now when I ssh into ubuntu and do ls, the folder called gametest is highlighted in green. What does that mean? Also, how can I change the rights of a user? I've just sort of stumbled into this because I'm trying to learn Node JS haha. Thanks a lot for your help! – swagrov Dec 31 '16 at 1:56
1

As noted in comments, try with

scp -v -r -i node.pem /Users/path/to/file/gametest ubuntu@35.164.71.227:

so the gametest directory is created in the server.

the folder called gametest is highlighted in green. What does that mean?

The green color depends on your environment configuration, it can mean that it is a directory, or specify its permissions, like if it writable or readable.

0

There are a few things to troubleshoot, let's try them one at a time.

I keep getting permission denied

Check that your permissions for the key file are correct. Here is a good walk through of the steps to take. Basically, move the key to `~/.ssh/ and set its permissions while also making sure it is attached in the AWS control panel (that second part is correct since you can SSH in already).

the folder called gametest is highlighted in green. What does that mean?

Green highlighted items in the terminal are executable or data files, not folders.

I am trying to copy over a folder called gametest

Try this on the server: cd && mv gametest gametest.bak && mkdir ~/gametest (that's a chain of commands to 1- change directory to your user's /home, 2- move the file you currently have at ~/gametest to a new file called 'gametest.bak', and 3- make a new directory ~/gametest at the root of your user's /home).

Next try your original command on your local machine. It should all work now work but if not we need some more clues.

To monitor the SSH log on the server, run this to monitor the error log in one terminal while you retry the failing command in a second terminal window: tail -f /var/log/auth.log. Press CTRL + C to cancel the error log monitoring.

I suspect the root cause of the problem is the fact that you were trying to copy a directory to a file on the server, not a directory, and that the cd && mv gametest gametest.bak && mkdir ~/gametest step above fixes things but do post an edit or comment if that doesn't fix the problem for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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