I
I
I_dont_known2016-04-20 16:28:09
linux
I_dont_known, 2016-04-20 16:28:09

How to open/create a file under another user?

I was puzzled by the transfer of my library to Linux, but I have no experience. The plug turned out with access rights - you need to create or open a file from under another user (creds are known). Under Windows did LogonUser + ImpersonateLoggedOnUser + CreateFile. How to do it correctly under Linux? I would be grateful if you could provide links to articles or literature.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
C
CityCat4, 2016-04-20
@CityCat4

No way. This is contrary to the ideology of linukh. System configs belong to root. Dot. No one except the root should rule them. Dot. If the program can have user settings, it must create its own local user config, which will be read after the system one. No user-run library should write to rootspace - the user only writes to homework and /tmp. And even more so, you should not do it on the sly.
All the problems of Windows are due to the fact that once, for the sake of convenience, they made it possible to write to anyone anywhere. In Linux, this is not the case. This should be taken for granted, and not sculpted with crutches. If this is a library for individual personal use, then of course you can turn back anything you like. But if you expect someone else to use it, it's better to follow the Linux way.

S
Saboteur, 2016-04-20
@saboteur_kiev

It is incorrect to create and open files under another user.
Why not add all the necessary users to the group, and use group rights?
The second option is to give the user the right to sudo, then he can execute su as root (to execute a command from another user), or execute the chown command (change owner) as root.
The third option is to configure ssh keys on the local machine for the user in order to he could execute commands via remsh
remsh [email protected]

D
Danil Biryukov-Romanov, 2016-04-20
@urtow

There is sudo to temporarily elevate rights, but you need to understand that the proposed solution is completely contrary to the access policy in Linux

P
Pavel Selivanov, 2016-04-20
@selivanov_pavel

It's easier to create a file and give the right user rights to it. If you need to create it directly from under another user - man7.org/linux/man-pages/man2/setuid.2.html man7.org/linux/man-pages/man2/seteuid.2.html

D
Dmitry, 2016-04-20
@plin2s

sudo -i -u

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question