Linux User Creation: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 168: Line 168:
|valign="top"|
|valign="top"|
<syntaxhighlight lang="bash">
<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>
</syntaxhighlight>
|}
|}
Line 181: Line 212:
|valign='top'|
|valign='top'|
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
    sudo useradd -m academia
      sudo useradd -m academia
cat /etc/shadow|grep academia
sudo chsh -s /bin/bash academia
cat /etc/passwd|grep academia
cat /etc/shadow|grep   academia
cat /etc/group |grep academia
cat /etc/passwd|grep   academia
</syntaxhighlight>
</syntaxhighlight>


Line 201: Line 232:
cat /etc/passwd|grep academia
cat /etc/passwd|grep academia
cat /etc/group |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>
</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