2

Suppose I am logged in as user A on a PC. On the same PC there is another user B. I want to move certain files from user's B home folder to A's home folder. Note that neither A nor B are sudo. However, I know the password of both users. What can I do?

PD: I know a workaround using scp (and then rm the source files). However that has the downside of copying the files, which can be very slow for large files, while mv would be instantaneous because it is a local operation. I want a solution that actually moves the files.

a06e
  • 14,233

3 Answers3

1

A cannot directly move a folder from B's home folder without sudo

So we will create a folder with lowered security in B's home

  1. Login as B and type:

    b@remote_computer:~$ mkdir tobemoved

This will create a folder /home/b/tobemoved

Move whatever files and folder you want to move inside this folder

For example if you want to move a file from the Documents folder:

b@remote_computer:~$ mv ~/Documents/somefile ~/tobemoved/

This will also work if you want to move somefolder instead of somefile.

Lower the read write delete permission for everything within the folder tobemoved

b@remote_computer:~$ chmod -R 777 tobemoved

Note: now anyone with an account in this computer can read, copy, delete and modify the files in this folder!

Log out and log back in as A

This is so that you want to move B's files to A's home

Create a folder to keep the files from B

a@remote_computer:~$ mkdir a_folder_to_keep_files_from_b

Move the files

a@remote_computer:~$ mv /home/b/tobemoved /home/a/a_folder_to_keep_files_from_b/

Hope this helps

user68186
  • 37,461
0

No way without sudo.

  1. trial, failure – sudo

    su B
    # the command below works only with sudo
    sudo chown A:A /home/B/<your_file_name>
    su -c A 'mv /home/B/<your_file_name> /home/A/'
    
  2. trial, failure – multiple mv and wrong ownership <your_file_name>

    su A
    mkdir incoming
    chmod 777 incoming
    su B
    mv /home/B/<your_file_name> /home/A/incoming
    su A
    mv /home/A/incoming/<your_file_name> /home/A/<your_final_target>
    
A.B.
  • 92,125
0

You can't do this without super user access unless you can circumvent permissions somehow, whether by having an interim directory that both users have r/w access to or using a FAT formatted external device (requiring physical access). If you have physical access to the hardware you can do whatever you want of course. Since you have access to both accounts you could transfer the files via an ftp server or a file sharing service.

Elder Geek
  • 36,752