# Τρέχων χρήστης
id -u
# ή
echo $UID
# Συγκεκριμένος χρήστης
id -u username
# Πλήρης info
id username
Έξοδος: uid=1000(john) gid=1000(john) groups=1000(john),27(sudo),998(docker)
import os, pwd
# Current user
print(os.getuid())
# By username
try:
entry = pwd.getpwnam("john")
print(entry.pw_uid)
except KeyError:
print("User not found")
#include
#include
#include
uid_t my_uid = getuid(); // Current process real UID
uid_t euid = geteuid(); // Effective UID
// By name (requires privileges for other users)
struct passwd *pw = getpwnam("john");
if (pw) printf("UID: %d\n", pw->pw_uid);
Μορφή: username:x:UID:GID:GECOS:home:shell. Το UID είναι το **3ο πεδίο** (0-indexed 2). Χρησιμοποιήστε `getent passwd username` για portability (λειτουργεί και με LDAP/SSSD).
Τα Windows **δεν χρησιμοποιούν UID**. Χρησιμοποιούν **SID** (π.χ. S-1-5-21-3623811015-3361044348-30300820-1001). Είναι καθολικά μοναδικά, μεταφερτά μεταξύ μηχανών (domain), και περιέχουν Relative Identifier (RID) στο τέλος.
# Όλοι οι χρήστες
wmic useraccount get name,sid
# PowerShell (πιο πλούσιο)
Get-LocalUser | Select-Object Name, SID, Enabled, LastLogon
# Τρέχων χρήστης
whoami /user
# pip install pywin32
import win32security, win32api
# Current user SID
token = win32security.OpenProcessToken(win32api.GetCurrentProcess(), win32security.TOKEN_QUERY)
sid = win32security.GetTokenInformation(token, win32security.TokenUser)[0]
print(win32security.ConvertSidToStringSid(sid))
# By username (requires admin for others)
sid, domain, type = win32security.LookupAccountName(None, "john")
print(win32security.ConvertSidToStringSid(sid))
drvfs metadata plugin.| Χαρακτηριστικό | Linux/macOS (UID) | Windows (SID) |
|---|---|---|
| Μορφή | Integer (32-bit) | String S-1-5-21-...-RID |
| Εύρος | Local to machine (0=root, 1000+=users) | Global unique (Domain + RID) |
| Αλλαγή | Μπορεί (usermod -u) – ρισκάρω | Ποτέ (immutable) |
| Αποθήκευση | /etc/passwd, LDAP, NIS | SAM (local), AD (domain) |
| Χρήση σε FS | inode uid/gid | NTFS ACL (ACE με SID) |
SeDebugPrivilege ή Domain Admin.Linux/macOS: id -u username ή pwd.getpwnam(). Windows: whoami /user ή Get-LocalUser | Select Name, SID. Κατανοήστε τη διαφορά: UID = local integer, SID = global unique string. Επιλέξτε το σωστό εργαλείο για το περιβάλλον σας.
Πνευματικά δικαιώματα © Γνώση Υπολογιστών Όλα τα δικαιώματα διατηρούνται.