Skip to content

Instantly share code, notes, and snippets.

@jijosg
Last active March 3, 2022 04:18
Show Gist options
  • Save jijosg/803759c8c4c28a31470cd5a6976dcac1 to your computer and use it in GitHub Desktop.
Save jijosg/803759c8c4c28a31470cd5a6976dcac1 to your computer and use it in GitHub Desktop.
Creating a user in Linux

The following commands show how to create a user named jijo in different distros

Creating a user in Ubuntu

useradd -ms /bin/bash jijo
#or
useradd --create-home --shell /bin/bash jijo

Creating a user in SLES

SLES doesnot have the useradd command so we have to do it the hard way 😄

echo "jijo:x:1000:1000::/home/jijo:/bin/bash" >> /etc/passwd
echo "jijo:x:1000:" >> /etc/group
mkdir -p /home/jijo
chown jijo:jijo /home/jijo

Sample dockerfile

# syntax=docker/dockerfile:1.3-labs

FROM ubuntu:focal-20220105

# Set up a custom user jijo 

RUN <<EOF
useradd --create-home --shell /bin/bash jijo
apt-get update
apt-get install --no-install-recommends -y git=2.25.1
apt-get clean
rm -rf /var/lib/apt/lists/*
EOF

USER jijo
WORKDIR /home/jijo
RUN whoami
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment