Linux cross-user copy files

Source: Internet
Author: User

Foo User home Directory has a file file.txt, to copy it to the bar user's home directory. Linux has strict permissions on the user's home directory, not the owner or the same group user without permission to read and write, unless it is root (the root of the supremacy). If there is no root authority, what is the way to copy the file.txt to the bar user's home directory?

Workaround:

The first way, first with the Foo user login, copy the file to the system temp directory/tmp, and then switch to the bar user, and then from the system temp directory/tmp to copy the files to their home directory. Why use CP here without MV? Because the file copied to/tmp is owner or foo, by default other users have Read permission, no write permission (naturally no move permission). Even if you make bar writable by modifying the file permissions, move to the bar's home directory owner or Foo, and you have to root to change to bar. This approach is a bit tortuous, the drawbacks are obvious, the file needs to be duplicated two times, spending twice times the time.

# CP file.txt/tmp/

# Su-bar

# Cp/tmp/file.txt ~/

# exit

# Rm/tmp/file.txt

The second approach, use the SCP command. Originally SCP was used to copy files over the network on different hosts, just right here. Log in with bar user

# SCP [email protected]:/home/foo/file.txt. /

Enter the Foo user password to start the file transfer. You can also log in with the Foo user,

# SCP file.txt [email protected]:/home/bar/

Enter the bar user password, as in the procedure.

Recommended Method Two

Linux cross-user copy files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.