Linux User Accounts
Linux is a multiuser OS, which means that multiple individuals can use the computer. Each user has an account.
Account Features
- account features are described in
/etc/passwd- consists of colon-delimited lines for each account
- e.g.,
rich:x:1001:1001:Richard Blum:/home/rich:/bin/bash
- e.g.,
- Username
- name of the account
- consists of lowercase letters and numbers, and potentially underscores and dashes
- Password
- Account is protected by a password
- password is stored in
/etc/shadow
- UID
- username is just a label that the computer displays for humans
- the computer uses a user identification (UID) number to track accounts
- begins with
0(root account) - most distributions start user account UIDs at
1000- reserve lower numbers for system accounts
- GID
- accounts are tied to one or more groups
- each account is tied directly to a primary group via a group ID (GID) number
- groups are used to specify permissions to multiple accounts
- Comment Field
- normally holds the user’s full name
- but can hold other information too
- normally holds the user’s full name
- Home Directory
- a home directory is an account’s home base
- ownership belongs to the account
- Default Shell
- a default shell is associated with every account
- normally Bash
- but can be changed
- most non-root system accounts set default shell to
/usr/sbin/nologinas a security measure- this program displays a message stating that the account is not available
- consists of colon-delimited lines for each account
- account passwords are stored in
/etc/shadow- ordinary users cannot read
- file associates salted and hashed password, and other info, with an account
- e.g.,
rich:$6$E/moFkeT5UnTQ3KqZUoA4Fl2tPUoIc[...]:18114:5:30:14:-1:-1:- Username
- Password
- password is salted and hashed
*or!denotes an account with no password- common for system accounts
- Last Password Change
18114is the data of the last password change- stored as the number of days since January 01, 1970
- Days Until a Change is Allowed
- next field is the number of days before a password change is allowed
- used to prevent users from changing passwords then changing them back to original
- Days Before a Change is Required
- This field is the number of days before another password change is required
- Days of Warning Before Password Expiration
- if system is configured to expire passwords
- may set a warning to users when an expiration date is approaching
- default value of 7
- Days Between Expiration and Deactivation
- Linux allows a gap between when the account expires and when it is deactivated
- expired account requires a user change the password immediately after logging in
- a deactivated account’s password is erased and cannot be used until reactivated by a system admin
-1indicates this feature is disabled
- Expiration Date
- shows the date on which the account will expire
-1indicates the feature is disabled
- Special Flag
- field is reserved
Identifying Accounts
- Can use the Users and Groups tool from the Menu GUI
- has limited use
- does not display system accounts
- Viewing the
/etc/passwdfile- reveals all accounts, both system and user
- can
grepa specific user accounts information - can use
gententcommand to retrieve entries from admin databases- e.g.,
getent passwd richto display account info - uses both local accounts and network server accounts
- e.g.,
Understanding Groups
Groups are collections of accounts defined in the /etc/group file.
- contains colon-delimited lines, each defining a single group
- e.g.,
users:x:100:games,christine - fields include:
- Group Name
- first field is the name of the group
- can be used with most commands that access or manipulate group data
- Password
- groups can have passwords
- a value of
xmeans that the password is defined elsewhere - empty field means there is no password
- GID
- Linux uses GID values internally
- User List
- specifies which users belong to the group in a comma-delimited list
- Group Name
- identifying members of a group:
- Specifying the group’s GID in user’s individual
/etc/passwdentry- user only has one GID in the entry, which is the default/primary group
- Specifying usernames in the user list in the
/etc/groupfile- single user can appear in multiple group entries
- single group can have multiple groups
- Specifying the group’s GID in user’s individual
- files created by an account are associated with its primary group
- to associate with a different group:
newgrp project1makesproject1the account’s current group- files created will now be associated with that group
- to associate with a different group:
Account Tools
whoamicommand displays current user accountiddisplays UID, GID, and all group memberships of the current user account- can specify a different user
whoto view all users logged in, whether via SSH or virtual terminal- shows:
- username
- terminal identifier
- login data and time
- remote host
- pulls data from
/var/run/utmpfile -q(--count) provides a more compact summary of the information
- shows:
wis similar towhobut produces more verbose output
Root Account
The root account has full privileges to manage the computer.
- aka super user or administrator
- used to perform administrative tasks
- include:
- installing new software
- preparing a new disk
- managing ordinary user accounts
- include:
- can read and write every file on the computer
Acquire Root Privileges
- Log in as
root- via shell or ssh
- login via GUI is typically blocked
suenables you to change identity within a shellsu namechanges identity to that user account- no option assumes
root - must know the target account password
exitto quit- use
-coption to run a single command - use
su - userto run a user’s login scripts- important for environment variables
sudoruns one command