LoginSignup
0
0

passwdとshadowとgroupを結合

Last updated at Posted at 2023-05-22
#!/bin/bash

# プライマリグループ名を取得するための辞書を作成します。
declare -A primary_group
while IFS=: read -r user pass uid gid rest; do
  primary_group["$user"]=$(getent group "$gid" | cut -d: -f1)
done </etc/passwd

# ユーザー情報とプライマリ・セカンダリグループを表示します。
while IFS=: read -r user pass uid gid gecos home shell; do
  primary=${primary_group["$user"]}
  secondary=$(id -Gn "$user" | tr ' ' '\n' | grep -v "^${primary}$" | paste -sd, -)

  shadow_info=$(getent shadow "$user")
  min=$(echo "$shadow_info" | cut -d: -f4)
  max=$(echo "$shadow_info" | cut -d: -f5)
  warn=$(echo "$shadow_info" | cut -d: -f6)
  inactive=$(echo "$shadow_info" | cut -d: -f7)
  password_hash=$(echo "$shadow_info" | cut -d: -f2)

  echo "$user:$uid:$gid:$primary:$secondary:$home:$shell:$min:$max:$warn:$inactive:$password_hash"
done </etc/passwd | sort -t: -k2 -n
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0