Ubuntu – Move file to another user’s home directory (without sudo)

mvpermissionsscp

I have a couple of files that I want to move to another's user home directory. I don't have permissions to write to that user's home directory, but I know his password.

I know how to copy the file using scp (see here). However, if I want to move the file, copying and then removing the original file is inefficient. Is there a way to move the file, without using sudo (I don't know the root's password)?

Best Answer

You can:

  1. Make your home directory world-readable and writeable.
  2. Login into his account.
  3. Move your files to his directory.
  4. Change ownership of said files.
  5. Logout of his account.
  6. Revert permissions of your home directory.

Detailed Step-by-Step Guide

Assume you're becko and you want to move the files to bob's home directory. Thus the paths for your homes are as follows (by default):

becko: /home/becko/
bob: /home/bob/

Now let's say the paths of the files you want to move are as follows:

/home/becko/file_01
/home/becko/file_02
/home/becko/file_03

Now, with this introduction, we can start.

NOTE: This example assumes all relevant files are one level below your home directory.

Step One: Make your home directory world-readable and writeable

While logged in as yourself, open a terminal (Ctrl+Alt+T).

Go to your home directory and make it world-readable:

$ cd ~
$ chmod 0777 .

Step Two: Login into his Account

Then, using the example provided above:

$ su - bob

You'll be prompted with his password.

Step Three: Move your files to his directory

After you login, you should see the following prompt (or something close to it):

bob@hellsdesk:~$ 

Now you are in bob's home directory. Now, time to move your stuff over.

The following commands should do it:

$ mv /home/becko/file_01 .
$ mv /home/becko/file_02 .
$ mv /home/becko/file_03 .

Step Four: Change Ownership of Files:

NOTE: For me, the ownership changed to bob automatically, but might as well be safe than sorry. :)

Commands:

$ chown bob:bob file_01
$ chown bob:bob file_02
$ chown bob:bob file_03

Step Five: Logout of His Account

This one's easy. Type:

$ logout

Your prompt should then change back to something like:

becko@hellsdesk:~$

Step Six: Revert your home directory permissions.

By default, the permissions are 0755. So, we'll do that:

$ chmod 0755 .

Close the terminal and you're done!

Related Question