scp to AWS EC2 - error - "Please login as the user "ubuntu" rather than the user "root"."
Solution 1
If you are getting the error you list then you are not specifying "ubuntu@" in the scp command, or you have copied the /root/.ssh/authorized_keys file to /home/ubuntu/.ssh/authorized_keys (which would be bad as you could then not log in with ssh).
It is true that once you do start specifying "ubuntu@" you will get a permissions error, but you can get around this using a command like this:
rsync -vazSHAX --rsync-path "sudo rsync" LOCALILE ubuntu@HOST:/var/www/REMOTEFILE
The key here is the --rsync-path option.
The rsync command will even let you copy whole directory trees as in:
rsync -vazSHAX --rsync-path "sudo rsync" LOCALDIR/ ubuntu@HOST:REMOTEDIR/
If you started the instance with a keypair generated by EC2 then you may also need to specify this option in rsync pointing to the local copy of the downloaded ssh key:
--rsh "ssh -i KEYPAIR.pem"
Here's an article I wrote about how to use sudo, ssh, rsync on Ubuntu EC2 instances:
Using sudo, ssh, rsync on the Official Ubuntu Images for EC2
http://alestic.com/2009/04/ubuntu-ec2-sudo-ssh-rsync
Here's an article where I explain how to upload your default personal ssh key to EC2 so that ssh and rsync don't need extra identity options:
Uploading Personal ssh Keys to Amazon EC2
http://alestic.com/2010/10/ec2-ssh-keys
Solution 2
I came here looking for an answer to this problem as well.
In my case though I had incorrectly copied the ~root/.ssh/authorized_keys
to another account, instead of copying my intended ~ubuntu/.ssh/authorized_keys
.
The root user authorized_keys
file has a specific command in it that disallows connection.
Solution 3
You can. Create a group, say "www-admin", add your username to that group, chown /var/www/fileremote to :www-admin, and chmod that path to allow group write.
Of course, if the path has been chown-ed to something else (non-default group), that group will lose all access. But in this case, just add your username to that group.
Related videos on Youtube
kalaracey
Updated on September 18, 2022Comments
-
kalaracey over 1 year
I'm trying to scp a file to /var/www because I'm playing with apache. To move the file I do
scp -i <ec2-shh-key> localfile root@<ec2-instance-ip>:/var/www/fileremote
.But this gives me an error:
Please login as the user "ubuntu" rather than the user "root".
How can I solve this problem?
EDIT: I have discovered this superuser question which answers the question by first scp'ing the file to a non-sudo dir, then passing a sudo mv command over ssh to move the file. Is there no way to do this in one step with just scp?
-
kalaracey almost 12 yearsOk, I'm sorry, I did make an error in my question -- I was in fact doing
root@<ec2-inst-ip>
; nevertheless, your answer solves my problem. Thanks for the good links.