If you are looking for software to use, go to Huajun Software Park! software release

How to copy files to other users in Linux?

Author: Five Horses Acacia Date: 2017-05-05

MIDI Editor MidiEditor for Linux
MIDI Editor MidiEditor for Linux-3.0.0

media tools Storage size: 0.75MB Time: 2010-05-18

Software introduction: MidiEditor is a free MIDI editor that supports Windows and Linux operating systems. The software is all written in C++ and QT, and...

Download now

In the Linux system, many people don’t know how to copy files between different users. In fact, there are many ways to copy files to another user. Today I will introduce to you two methods of copying files to other users in Linux. Let’s learn together.

QQ screenshot 20170505140636.jpg

scene:

There is a file file.txt in the home directory of user foo, which needs to be copied to the home directory of user bar. Linux has strict permission restrictions on user home directories. Non-owner users or users in the same group have no permission to read or write, unless they are root (the supreme root). If you don't have root permissions, is there any way to copy file.txt to the home directory of user bar?

Solution:

The first method is to log in as the foo user, copy the file to the system temporary directory/tmp, then switch to the bar user, and then copy the file from the system temporary directory/tmp to your home directory. Why use cp instead of mv here? Because the owner of the file copied to /tmp is still foo, by default other users have read permissions but no write permissions (and naturally no move permissions). Even if you modify the file permissions to make bar writable, the owner will still be foo under the home directory of bar, and you must be root to change it to bar. This method is a bit tortuous and has obvious drawbacks. The file needs to be copied twice and takes twice as long.

# cp file.txt /tmp/

#su-bar

# cp /tmp/file.txt ~/

#exit

# rm /tmp/file.txt

The second way is to use the scp command. Originally scp was used to copy files over the network on different hosts, so it is suitable for use here. Log in as user bar

# scp foo@localhost:/home/foo/file.txt. /

Enter the foo user password to start the file transfer. You can also log in as user foo,

# scp file.txt bar@localhost:/home/bar/

Enter the bar user password and the process is the same.

       Okay, the above is all the content brought to you by the editor of Huajun. Isn’t it very simple? Have you learned it? If you want to know more related content, please pay attention to Huajun information updates at any time. Welcome to Huajun to download!

Related articles