Linux User Creation: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
 
(12 intermediate revisions by the same user not shown)
Line 4: Line 4:
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
cat << EXE | sudo bash
cat << EXE | sudo bash
CHORKE_SYS_USERS='activemq artemis hadoop spark keycloak minikube minio wildfly'
SYSTEM_SYS_USERS='activemq artemis hadoop spark keycloak minikube minio wildfly'
for SSH_USER in \${CHORKE_SYS_USERS};do
for SYS_USER in \${SYSTEM_SYS_USERS};do
   if ! id -g \${SSH_USER} &>/dev/null;then addgroup --quiet --system \${SSH_USER};fi
   if ! id -g \${SYS_USER} &>/dev/null;then addgroup --quiet --system \${SYS_USER};fi
   if ! id -u \${SSH_USER} &>/dev/null;then
   if ! id -u \${SYS_USER} &>/dev/null;then
     adduser --quiet --system --ingroup \${SSH_USER} --home /nonexistent --shell /usr/sbin/nologin --disabled-password \${SSH_USER}
     adduser --quiet --system --ingroup \${SYS_USER} --home /nonexistent --shell /usr/sbin/nologin --disabled-password \${SYS_USER}
   fi
   fi
done
done
Line 22: Line 22:
cat << EXE | sudo bash
cat << EXE | sudo bash
mkdir -p /home/system/
mkdir -p /home/system/
CHORKE_SYS_USERS='academia agronomy assembla aviation commando crafting'
SYSTEM_SYS_USERS='activemq artemis hadoop spark keycloak minikube minio wildfly'
for SSH_USER in \${CHORKE_SYS_USERS};do
for SYS_USER in \${SYSTEM_SYS_USERS};do
   if ! id -g \${SSH_USER} &>/dev/null;then addgroup --quiet --system \${SSH_USER};fi
   if ! id -g \${SYS_USER} &>/dev/null;then addgroup --quiet --system \${SYS_USER};fi
   if ! id -u \${SSH_USER} &>/dev/null;then
   if ! id -u \${SYS_USER} &>/dev/null;then
     adduser --quiet --system --ingroup \${SSH_USER} --home /home/system/\${SSH_USER} --shell /bin/bash --disabled-password \${SSH_USER}
     adduser --quiet --system --ingroup \${SYS_USER} --home /home/system/\${SYS_USER} --shell /bin/bash --disabled-password \${SYS_USER}
     chage -m 99999 -M 99999 -E -1 -I -1  \${SSH_USER}
     chage -m 99999 -M 99999 -E -1 -I -1  \${SYS_USER}


     mkdir /home/system/\${SSH_USER}/.ssh
     mkdir /home/system/\${SYS_USER}/.ssh
     touch /home/system/\${SSH_USER}/.ssh/config
     touch /home/system/\${SYS_USER}/.ssh/config
     touch /home/system/\${SSH_USER}/.ssh/authorized_keys
     touch /home/system/\${SYS_USER}/.ssh/authorized_keys


     chown -R \${SSH_USER}:\${SSH_USER} /home/system/\${SSH_USER}/
     chown -R \${SYS_USER}:\${SYS_USER} /home/system/\${SYS_USER}/
     chmod 600 /home/system/\${SSH_USER}/.ssh/authorized_keys
     chmod 600 /home/system/\${SYS_USER}/.ssh/authorized_keys
     chmod 600 /home/system/\${SSH_USER}/.ssh/config
     chmod 600 /home/system/\${SYS_USER}/.ssh/config
     chmod 700 /home/system/\${SSH_USER}/.ssh
     chmod 700 /home/system/\${SYS_USER}/.ssh
   fi
   fi
done
done
Line 52: Line 52:
cat << EXE | sudo bash
cat << EXE | sudo bash
mkdir -p /home/devops/
mkdir -p /home/devops/
DEVOPS_SSH_USER='argo.cd drone.ci tool.tech raiyan.shahed shahed.hossain'
DEVOPS_EXT_USERS='argo.cd drone.ci tool.tech raiyan.shahed shahed.hossain'
for SSH_USER in \${DEVOPS_SSH_USER};do
for EXT_USER in \${DEVOPS_EXT_USERS};do
   if ! id -u \${SSH_USER} &>/dev/null;then
   if ! id -u \${EXT_USER} &>/dev/null;then
     useradd --create-home --home-dir /home/devops/\${SSH_USER} --shell /bin/bash \${SSH_USER}
     useradd --create-home --home-dir /home/devops/\${EXT_USER} --shell /bin/bash \${EXT_USER}
     chage -m 99999 -M 99999 -E -1 -I -1  \${SSH_USER}
     chage -m 99999 -M 99999 -E -1 -I -1  \${EXT_USER}


     mkdir /home/devops/\${SSH_USER}/.ssh
     mkdir /home/devops/\${EXT_USER}/.ssh
     touch /home/devops/\${SSH_USER}/.ssh/config
     touch /home/devops/\${EXT_USER}/.ssh/config
     touch /home/devops/\${SSH_USER}/.ssh/authorized_keys
     touch /home/devops/\${EXT_USER}/.ssh/authorized_keys


     chown -R \${SSH_USER}:\${SSH_USER} /home/devops/\${SSH_USER}/
     chown -R \${EXT_USER}:\${EXT_USER} /home/devops/\${EXT_USER}/
     chmod 600 /home/devops/\${SSH_USER}/.ssh/authorized_keys
     chmod 600 /home/devops/\${EXT_USER}/.ssh/authorized_keys
     chmod 600 /home/devops/\${SSH_USER}/.ssh/config
     chmod 600 /home/devops/\${EXT_USER}/.ssh/config
     chmod 700 /home/devops/\${SSH_USER}/.ssh
     chmod 700 /home/devops/\${EXT_USER}/.ssh
   fi
   fi
done
done
Line 74: Line 74:
EXE
EXE
</syntaxhighlight>
</syntaxhighlight>
===DevOps » User » EdDSA Key===
----
<syntaxhighlight lang="bash">
cat <<'EXT'| sudo bash
DEVOPS_EXT_USERS='argo.cd drone.ci tool.tech raiyan.shahed shahed.hossain'
for EXT_USER in ${DEVOPS_EXT_USERS};do
    if id -u ${EXT_USER} &>/dev/null;then
        cat <<'EXE'| sudo -i -u ${EXT_USER} bash
if [ ! -e "${HOME}/.ssh/id_ed25519" ] && [ ! -e "${HOME}/.ssh/id_ed25519.pub" ];then
    ssh-keygen -t ed25519 -C "${USER}@shahed.biz" -N "" -q  -f ${HOME}/.ssh/id_ed25519
fi
cat ${HOME}/.ssh/id_ed25519.pub
EXE
    fi
done
EXT
</syntaxhighlight>
===DevOps » User » Delete===
----
<syntaxhighlight lang="bash">
cat << EXE | sudo bash
DEVOPS_EXT_USERS='ibrahim.sardar abdul.hakim shalina.begum'
for EXT_USER in \${DEVOPS_EXT_USERS};do
  if id -u \${EXT_USER} &>/dev/null;then
    userdel \${EXT_USER}
    rm -r /home/devops/\${EXT_USER}
  fi
done
echo && ls -alh /home/devops/
echo && cat /etc/passwd|awk -F : '\$3 >= 1000 && \$3 < 65500 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h
echo && cat /etc/group |awk -F : '\$3 >= 1000 && \$3 < 65500 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h && echo
EXE
</syntaxhighlight>
==User » Home » Change==
{|
|valign="top"|
<syntaxhighlight lang="bash">
cat <<'EXE'| sudo bash
  rsync -a /home/artemis /home/system/
              usermod -d /home/system/artemis artemis
chown artemis:artemis -R /home/system/artemis
    rm -rf /home/artemis
EXE
</syntaxhighlight>
|valign="top"|
<syntaxhighlight lang="bash">
cat <<'EXE'| sudo bash
  rsync -a /home/minikube /home/system/
                usermod -d /home/system/minikube minikube
chown minikube:minikube -R /home/system/minikube
    rm -rf /home/minikube
EXE
</syntaxhighlight>
|valign="top"|
<syntaxhighlight lang="bash">
cat <<'EXE'| sudo bash
rsync -a /home/minio /home/system/
          usermod -d /home/system/minio minio
chown minio:minio -R /home/system/minio
  rm -rf /home/minio
EXE
</syntaxhighlight>
|-
| colspan="3" |
----
|-
|valign="top"|
<syntaxhighlight lang="bash">
cat <<'EXE'| sudo bash
rsync -a /home/hadoop /home/system/
            usermod -d /home/system/hadoop hadoop
chown hadoop:hadoop -R /home/system/hadoop
  rm -rf /home/hadoop
EXE
</syntaxhighlight>
|valign="top"|
<syntaxhighlight lang="bash">
cat <<'EXE'| sudo bash
rsync -a /home/spark /home/system/
          usermod -d /home/system/spark spark
chown spark:spark -R /home/system/spark
  rm -rf /home/spark
EXE
</syntaxhighlight>
|valign="top"|
<syntaxhighlight lang="bash">
</syntaxhighlight>
|}
==User » Name » Change==
<syntaxhighlight lang="bash">
sudo usermod -l chorke deploy
sudo usermod -d /home/chorke -m chorke
sudo groupmod -n chorke deploy
</syntaxhighlight>
==User » Sudo » Privilege==
{|class='wikitable mw-collapsible mw-collapsed'
!scope='col' style='width:1000px'| <code>sudo visudo</code>
|-
|valign='top'|
<syntaxhighlight lang="ini" start='46' highlight='3,7,11' line>
# User privilege specification
root      ALL=(ALL:ALL) ALL
academia  ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin  ALL=(ALL) ALL
academia ALL=(ALL) NOPASSWD: /usr/local/bin/supervisorctl
# Allow members of group sudo to execute any command
%sudo    ALL=(ALL:ALL) ALL
academia ALL=(ALL) NOPASSWD: /usr/local/bin/supervisorctl
# See sudoers(5) for more information on "@include" directives:
@includedir /etc/sudoers.d
</syntaxhighlight>
|}
==User » Prevent » Password==
{|class='wikitable mw-collapsible'
!scope='col' colspan='3' style='width:1000px'| '''Linux » Create » Password less » User'''
|-
!scope='col'| Create  Resident User
!scope='col'| Delete  Password From User
!scope='col'| Prevent Password To Set
|-
|valign='top'|
<syntaxhighlight lang="bash">
      sudo useradd -m academia
sudo chsh -s /bin/bash academia
cat /etc/shadow|grep  academia
cat /etc/passwd|grep  academia
</syntaxhighlight>
|valign='top'|
<syntaxhighlight lang="bash">
      sudo passwd -d academia
cat /etc/shadow|grep academia
cat /etc/passwd|grep academia
cat /etc/group |grep academia
</syntaxhighlight>
|valign='top'|
<syntaxhighlight lang="bash">
      sudo passwd -l academia
cat /etc/shadow|grep academia
cat /etc/passwd|grep academia
cat /etc/group |grep academia
</syntaxhighlight>
|}
==User » Immutable » Authorization » Key==
{|class='wikitable mw-collapsible'
!scope='col' colspan='3' style='width:1000px'| '''Linux » Immutable » authorized_keys'''
|-
|valign='top'|
<syntaxhighlight lang="bash">
sudo chattr +i /home/academia/.ssh/authorized_keys #Immutable
sudo chattr -i /home/academia/.ssh/authorized_keys #  Mutable
</syntaxhighlight>
|}


==Playground==
==Playground==
Line 197: Line 368:
----
----
|-
|-
| valign="top" colspan="3" |
| valign="top" colspan="2" |
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
adduser --quiet --system --ingroup chorke --no-create-home    --shell /usr/sbin/nologin --disabled-password chorke
adduser --quiet --system --ingroup chorke --no-create-home    --shell /usr/sbin/nologin --disabled-password chorke
Line 203: Line 374:
</syntaxhighlight>
</syntaxhighlight>


| valign="top" |
<syntaxhighlight lang="bash">
chsh -s /bin/bash        chorke
chsh -s /usr/sbin/nologin chorke
</syntaxhighlight>
|}
|}



Latest revision as of 02:00, 6 July 2025

System » User

System » User » Homeless


cat << EXE | sudo bash
SYSTEM_SYS_USERS='activemq artemis hadoop spark keycloak minikube minio wildfly'
for SYS_USER in \${SYSTEM_SYS_USERS};do
  if ! id -g \${SYS_USER} &>/dev/null;then addgroup --quiet --system \${SYS_USER};fi
  if ! id -u \${SYS_USER} &>/dev/null;then
    adduser --quiet --system --ingroup \${SYS_USER} --home /nonexistent --shell /usr/sbin/nologin --disabled-password \${SYS_USER}
  fi
done

echo && cat /etc/passwd|awk -F : '\$3 >= 120 && \$3 < 900 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h
echo && cat /etc/group |awk -F : '\$3 >= 120 && \$3 < 900 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h && echo
EXE

System » User » Resident


cat << EXE | sudo bash
mkdir -p /home/system/
SYSTEM_SYS_USERS='activemq artemis hadoop spark keycloak minikube minio wildfly'
for SYS_USER in \${SYSTEM_SYS_USERS};do
  if ! id -g \${SYS_USER} &>/dev/null;then addgroup --quiet --system \${SYS_USER};fi
  if ! id -u \${SYS_USER} &>/dev/null;then
    adduser --quiet --system --ingroup \${SYS_USER} --home /home/system/\${SYS_USER} --shell /bin/bash --disabled-password \${SYS_USER}
    chage -m 99999 -M 99999 -E -1 -I -1  \${SYS_USER}

    mkdir /home/system/\${SYS_USER}/.ssh
    touch /home/system/\${SYS_USER}/.ssh/config
    touch /home/system/\${SYS_USER}/.ssh/authorized_keys

    chown -R \${SYS_USER}:\${SYS_USER} /home/system/\${SYS_USER}/
    chmod 600 /home/system/\${SYS_USER}/.ssh/authorized_keys
    chmod 600 /home/system/\${SYS_USER}/.ssh/config
    chmod 700 /home/system/\${SYS_USER}/.ssh
  fi
done

echo && ls -alh /home/system/*/.ssh/*
echo && cat /etc/passwd|awk -F : '\$3 >= 120 && \$3 < 900 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h
echo && cat /etc/group |awk -F : '\$3 >= 120 && \$3 < 900 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h && echo
EXE

DevOps » User

DevOps » User » Resident


cat << EXE | sudo bash
mkdir -p /home/devops/
DEVOPS_EXT_USERS='argo.cd drone.ci tool.tech raiyan.shahed shahed.hossain'
for EXT_USER in \${DEVOPS_EXT_USERS};do
  if ! id -u \${EXT_USER} &>/dev/null;then
    useradd --create-home --home-dir /home/devops/\${EXT_USER} --shell /bin/bash \${EXT_USER}
    chage -m 99999 -M 99999 -E -1 -I -1  \${EXT_USER}

    mkdir /home/devops/\${EXT_USER}/.ssh
    touch /home/devops/\${EXT_USER}/.ssh/config
    touch /home/devops/\${EXT_USER}/.ssh/authorized_keys

    chown -R \${EXT_USER}:\${EXT_USER} /home/devops/\${EXT_USER}/
    chmod 600 /home/devops/\${EXT_USER}/.ssh/authorized_keys
    chmod 600 /home/devops/\${EXT_USER}/.ssh/config
    chmod 700 /home/devops/\${EXT_USER}/.ssh
  fi
done

echo && ls -alh /home/devops/*/.ssh/*
echo && cat /etc/passwd|awk -F : '\$3 >= 1000 && \$3 < 65500 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h
echo && cat /etc/group |awk -F : '\$3 >= 1000 && \$3 < 65500 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h && echo
EXE

DevOps » User » EdDSA Key


cat <<'EXT'| sudo bash
DEVOPS_EXT_USERS='argo.cd drone.ci tool.tech raiyan.shahed shahed.hossain'
for EXT_USER in ${DEVOPS_EXT_USERS};do
    if id -u ${EXT_USER} &>/dev/null;then
        cat <<'EXE'| sudo -i -u ${EXT_USER} bash
if [ ! -e "${HOME}/.ssh/id_ed25519" ] && [ ! -e "${HOME}/.ssh/id_ed25519.pub" ];then
    ssh-keygen -t ed25519 -C "${USER}@shahed.biz" -N "" -q  -f ${HOME}/.ssh/id_ed25519
fi
cat ${HOME}/.ssh/id_ed25519.pub
EXE
    fi
done
EXT

DevOps » User » Delete


cat << EXE | sudo bash
DEVOPS_EXT_USERS='ibrahim.sardar abdul.hakim shalina.begum'
for EXT_USER in \${DEVOPS_EXT_USERS};do
  if id -u \${EXT_USER} &>/dev/null;then
    userdel \${EXT_USER}
    rm -r /home/devops/\${EXT_USER}
  fi
done

echo && ls -alh /home/devops/
echo && cat /etc/passwd|awk -F : '\$3 >= 1000 && \$3 < 65500 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h
echo && cat /etc/group |awk -F : '\$3 >= 1000 && \$3 < 65500 {printf("%-6s » %s\n", \$3, \$1)}'|sort -h && echo
EXE

User » Home » Change

cat <<'EXE'| sudo bash
  rsync -a /home/artemis /home/system/
              usermod -d /home/system/artemis artemis
chown artemis:artemis -R /home/system/artemis
    rm -rf /home/artemis
EXE
cat <<'EXE'| sudo bash
   rsync -a /home/minikube /home/system/
                usermod -d /home/system/minikube minikube
chown minikube:minikube -R /home/system/minikube
     rm -rf /home/minikube
EXE
cat <<'EXE'| sudo bash
rsync -a /home/minio /home/system/
          usermod -d /home/system/minio minio
chown minio:minio -R /home/system/minio
  rm -rf /home/minio
EXE

cat <<'EXE'| sudo bash
 rsync -a /home/hadoop /home/system/
            usermod -d /home/system/hadoop hadoop
chown hadoop:hadoop -R /home/system/hadoop
   rm -rf /home/hadoop
EXE
cat <<'EXE'| sudo bash
rsync -a /home/spark /home/system/
          usermod -d /home/system/spark spark
chown spark:spark -R /home/system/spark
  rm -rf /home/spark
EXE

User » Name » Change

sudo usermod -l chorke deploy
sudo usermod -d /home/chorke -m chorke
sudo groupmod -n chorke deploy

User » Sudo » Privilege

sudo visudo
# User privilege specification
root      ALL=(ALL:ALL) ALL
academia  ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin   ALL=(ALL) ALL
academia ALL=(ALL) NOPASSWD: /usr/local/bin/supervisorctl

# Allow members of group sudo to execute any command
%sudo    ALL=(ALL:ALL) ALL
academia ALL=(ALL) NOPASSWD: /usr/local/bin/supervisorctl

# See sudoers(5) for more information on "@include" directives:

@includedir /etc/sudoers.d

User » Prevent » Password

Linux » Create » Password less » User
Create Resident User Delete Password From User Prevent Password To Set
       sudo useradd -m academia
sudo chsh -s /bin/bash academia
cat /etc/shadow|grep   academia
cat /etc/passwd|grep   academia
      sudo passwd -d academia
cat /etc/shadow|grep academia
cat /etc/passwd|grep academia
cat /etc/group |grep academia
      sudo passwd -l academia
cat /etc/shadow|grep academia
cat /etc/passwd|grep academia
cat /etc/group |grep academia

User » Immutable » Authorization » Key

Linux » Immutable » authorized_keys
sudo chattr +i /home/academia/.ssh/authorized_keys #Immutable
sudo chattr -i /home/academia/.ssh/authorized_keys #  Mutable

Playground

lxc image list images:ubuntu/noble/desktop
lxc launch --vm images:ffa5fc9dfb84 cloudflare
lxc launch --vm images:ubuntu/noble/desktop cloudflare
lxc list status=running name=cloudflare --format=json |jq  -r '.[].state.network.[].addresses'
lxc list status=running name=cloudflare --format=yaml |yq  -r '.[].state.network.[].addresses'
lxc info cloudflare|yq '.Resources.["Network usage"][]["IP addresses"].inet'

ls -lah /usr/local/etc/cloudflared/
          ls -lah /etc/cloudflared/
            ls -lah ~/.cloudflared/
lxc snapshot cloudflare argo:24.04
lxc publish  cloudflare/argo:24.04 --alias cloudflare/argo:24.04
lxc restore  cloudflare argo:24.04

apt list --installed|grep linux-image
systemd-analyze blame
dpkg -l | grep "gnome-shell-extension"

systemctl list-dependencies graphical.target
cat /proc/acpi/wakeup
sudo apt list --installed|grep desktop-icons
sudo dpkg-query -l|grep desktop-icons
sudo apt install gnome-shell-extension-manager
apt info gnome-shell-extension-manager -a

cat <<-'EXE'|sudo bash
umount /var/snap/firefox/common/host-hunspell
snap remove firefox
EXE
cat <<-'EXE'|sudo bash
snap disable remmina
snap remove --purge remmina
EXE
systemctl list-dependencies --type=service --state=running
systemctl list-dependencies --type=service --state=active
systemctl list-dependencies docker.service
systemctl list-dependencies --all

cat /etc/passwd
cat /etc/group
cat /etc/passwd|\
awk -F : '$3 >= 1000 {printf("%-6s » %s\n", $3, $1)}'|sort -h
useradd -m -d /home/chorke -s /bin/bash chorke
useradd -m -d /home/chorke -s /bin/bash chorke

adduser --quiet --system --ingroup chorke --no-create-home    --shell /usr/sbin/nologin --disabled-password chorke
adduser --quiet --system --ingroup chorke --home /nonexistent --shell /usr/sbin/nologin --disabled-password chorke
chsh -s /bin/bash         chorke
chsh -s /usr/sbin/nologin chorke

References