Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have an Ubuntu server to which I am connecting using SSH.

I need to upload files from my machine into /var/www/ on the server, the files in /var/www/ are owned by root.

Using PuTTY, after I log in, I have to type sudo su and my password first in order to be able to modify files in /var/www/.

But when I am copying files using WinSCP , I can't create create/modify files in /var/www/, because the user I'm connecting with does not have permissions on files in /var/www/ and I can't say sudo su as I do in case of an ssh session.

Do you know how i could deal with this ?

If I was working on my local machine, I would call gksudo nautilus but in this case I only have terminal access to the machine.

share|improve this question
This seems more like a question for your virtual server provider, or for the putty or winscp developers. – dobey Oct 29 '12 at 21:17
@dobey you obviusly wrong , it is about ubuntu privileges ! – Dimitris Sapikas Oct 30 '12 at 10:14
Why is this closed? This is a perfectly valid question about copying files with scp - every web developer is familiar with this situation – Sergey Oct 30 '12 at 22:02
Copying protected files between servers in one line? should help. – Gilles Oct 30 '12 at 23:04

2 Answers

up vote 4 down vote accepted

You're right, there is no sudo when working with scp. A workaround is to use scp to upload files to a directory where your user has permissions to create files, then log in via ssh and use sudo to move/copy files to their final destination.

Another solution would be to change permissions/ownership of the directories you uploading the files to, so your non-privileged user is able to write to those directories.

Generally, working in the root account should be an exception, not a rule - the way you phrasing your question makes me think maybe you're abusing it a bit, which in turn leads to problems with permissions - under normal circumstances you don't need super-admin privileges to access your own files.

Technically, you can configure Ubuntu to allow remote login directly as root, but this feature is disabled for a reason, so I would strongly advice you against doing that.

share|improve this answer
i didn't get the first solution , could you please be a litle more spesific ? – Dimitris Sapikas Oct 30 '12 at 9:42
Whe i say my own files i mean /var/www , i am using my vps as web server .... on my own folder i have full access – Dimitris Sapikas Oct 30 '12 at 9:44
1  
Re. the first solution. 1. scp -R mysite dimitris@myserver.com:/home/dimitris/ 2. ssh dimitris@myserver.com 3. sudo mv ~/mysite /var/www - it's a 2-step process, first you scp the files to your home dir, then you log in via ssh and copy/move the files to where they should be – Sergey Oct 30 '12 at 21:58
hm.. it works fine ! thank you :) – Dimitris Sapikas Oct 31 '12 at 19:06

When you run sudo su, any files you create will be owned by root, but it is not possible by default to directly log in as root with ssh or scp. It is also not possible to use sudo with scp, so the files are not usable. Fix this by claiming ownership over your files:

Assuming your user name was dimitri, you could use this command.

sudo chown -R dimitri:dimitri /home/dimitri

From then on, as mentioned in other answers, the "Ubuntu" way is to use sudo, and not root logins. It is a useful paradigm, with great security advantages.

share|improve this answer
i am using this solution any way , but what if i could get full access to my own file system , i don't want to type sudo chow ... for every single directory :S – Dimitris Sapikas Oct 30 '12 at 9:47
Changing ownership of all system files to the user for passing convenience is highly discouraged. It allows any userspace bug you might encounter to severely compromise the security of your system. It is much better to change the ownership of the files that you need to change or update by SCP, but to leave everything else owned by root (like it is supposed to be). That said, the -R in chown tells it to change the ownership of that directory, and all children files and directories recursively... so you can do anything you like. – Bailey S Oct 30 '12 at 17:48
An upvote might be nice... – Bailey S Oct 30 '12 at 17:49
hmm .... that seems working fine , thank you ! sorry i can't upvote (system does not allow me to do ...) – Dimitris Sapikas Oct 30 '12 at 19:05

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.