Recent

Author Topic: Get/set Unix file 'owner'?  (Read 4349 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Get/set Unix file 'owner'?
« on: June 17, 2021, 09:12:07 pm »
CudaText runs 'pkexec /bin/cp old_filename new_filename'.
It works OK but the owner of that file changes from 'root' to my name.
Can I change the owner of a file?
Can I read the owner of a file?
« Last Edit: June 17, 2021, 09:22:23 pm by Alextp »

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Get/set Unix file 'owner'?
« Reply #1 on: June 17, 2021, 09:37:41 pm »
Hi!

The unit BaseUnix has a wapper for the Unix command chown:

Code: Pascal  [Select][+][-]
  1. Function  FpChown   (const path : RawByteString; owner : TUid; group : TGid): cInt;

Winni

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Get/set Unix file 'owner'?
« Reply #2 on: June 17, 2021, 10:00:02 pm »
To run the 'pkexec --user username' I need the string-user-name of file owner. How to get it?

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: Get/set Unix file 'owner'?
« Reply #3 on: June 17, 2021, 10:08:13 pm »
don't you need elevated rights (sudo) to assign "root" as the owner?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Get/set Unix file 'owner'?
« Reply #4 on: June 17, 2021, 10:08:42 pm »
Hi


Use the Unix command id:

To get the UserID:
Code: Bash  [Select][+][-]
  1.  
  2. id -u winni


To get the GroupId:


Code: Bash  [Select][+][-]
  1. id -g winni


Winni


winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Get/set Unix file 'owner'?
« Reply #5 on: June 17, 2021, 10:10:14 pm »
don't you need elevated rights (sudo) to assign "root" as the owner?

Yes

Winni

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Get/set Unix file 'owner'?
« Reply #6 on: June 17, 2021, 10:36:43 pm »
Hi!

Oops - you need it vice versa.

For UserId 1000  you use:

Code: Bash  [Select][+][-]
  1. grep - w 1000 /etc/passwd

It returns in my case:

Code: Text  [Select][+][-]
  1. winni:x:1000:100::/home/winni:/bin/bash


which is:

Code: Text  [Select][+][-]
  1. UserName:pwd:UserID:GroupID:comment:HomeDirectory:shell

Winni
« Last Edit: June 17, 2021, 10:41:29 pm by winni »

AlexTP

  • Hero Member
  • *****
  • Posts: 2365
    • UVviewsoft
Re: Get/set Unix file 'owner'?
« Reply #7 on: June 17, 2021, 11:21:28 pm »
Thanks.
I found that 'pkexec /bin/mv' does NOT set root owner. But 'pkexec /bin/cp filename /etc/filename' does it! Solved.

 

TinyPortal © 2005-2018