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.

8
  • See askubuntu.com/questions/291501/…
    – user68186
    Jun 9, 2015 at 17:31
  • @user68186 The question you link has a solution that requires a graphic interface. I am doing this at a remote server, that doesn't have GUI. How can I do it from the terminal? Also, remember I'm not sudo.
    – becko
    Jun 10, 2015 at 18:43
  • With only one mv per file?
    – A.B.
    Jun 10, 2015 at 19:20
  • @A.B. I'm not sure I understand your question. To me it is not important how many times you call mv. As long as it is faster than a copy.
    – becko
    Jun 10, 2015 at 19:26
  • 1
    Are the users in the same group? does the file need to change user and group to the new user?
    – Rinzwind
    Jun 11, 2015 at 7:39

3 Answers 3

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

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>
    
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.

4
  • Can I create somehow a directory where both users have r/w access? Like sharing?
    – becko
    Jun 11, 2015 at 12:49
  • That depends on how securely the system is set up, but I would assume no or you wouldn't have this question. You can create whatever you want in your own home directory and same for the other user, however you need to be able to traverse the other users directory which is beyond your ability to change without super user access. Ask the administrator or gain physical access to the machine.
    – Elder Geek
    Jun 11, 2015 at 12:55
  • I know the passwords for both users A and B. So I can login either of them as required. Wouldn't that help?
    – becko
    Jun 11, 2015 at 13:40
  • The consensus appears to be no. Did you try user68186 answer?
    – Elder Geek
    Jun 11, 2015 at 19:38

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.