linux-cheatsheet

A cheatsheet with common linux commands and tools

View on GitHub

Users and authentication

Learn about elevated privileges (sudo mode), users, groups and user authentication.

Elevated privileges & switching users

sudo commands are only allowed for users listed in /etc/sudoers (or, by default, in the wheels group).

Users

Users are stored in the /etc/passwd file.

The alternatives adduser and deluser have more prompts but do more or less the same.

Understanding /etc/passwd

rafael:x:1001:1001:rafael,,,:/home/rafael:/bin/bash
[----] - [--] [--] [-------] [----------] [-------]
|      |   |    |      |          |         |
|      |   |    |      |          |         +------> 7. Login shell
|      |   |    |      |          +----------------> 6. Home directory
|      |   |    |      +---------------------------> 5. GECOS (user infos)
|      |   |    +----------------------------------> 4. GID (group id)
|      |   +---------------------------------------> 3. UID (user id)
|      +-------------------------------------------> 2. Password (nowadays "x"; password in /etc/shadow)
+--------------------------------------------------> 1. Username

Deactivate login for user: Set login shell to /usr/sbin/nologin setzen.

Groups

Groups are stored in the /etc/group file.

Manage group membership:

Commands available on some distros:

Understanding /etc/group

wheel:x:10:rafael,fritz
[---] - -- [----------]
|     |  |      |
|     |  |      +------> 4. Members (comma separated)
|     |  +-------------> 3. GID (group id)
|     +----------------> 2. Password (nowadays "x"; password in /etc/gshadow)
+----------------------> 1. Group name

Group passwords are usually not used.

Password authentication

Info about user and group authentication is stored in /etc/shadow and /etc/gshadow.

Note: Group passwords are not really used anymore.

Understanding /etc/shadow and /etc/gshadow

Encryption algorithms

  1. MD5
  2. bcrypt
  3. -
  4. -
  5. sha256
  6. sha512

Passwords

SSH

Generated keys are stored in ~/.ssh/ with the names ...id_rsa and ...id_rsa.pub (name changes depending on options).

Authorized keys are stored in ~/.ssh/authorized_keys.

SSH Config

File: ~/.ssh/config Example content:

Host *
   ForwardX11 no

Host prod-de-1
   HostName 192.168.1.125
   User admin
   IdentityFile ~/.ssh/work_key
   Port 2222


This cheatsheet was created by Rafael Urben. Found a mistake? Feel free to create a PR or open an issue on GitHub!