Linux from scracth
Linux from scracth
User Administrator
#useradd= for add user
#id = for check the which user ,group your are in
#gdisk - used for create partitions
#cat /etc/login.defs- this is the configuration file
#id - used for define user identification
root user id always 0 uid gid
system user id btewn 1-999
normal user id is frm 1000 to 60000
for customizing user identifier
# vi /etc/login.dfs & edit the user identifier
if you create a user bydefault group also create that is primary group , if you
have already have group you can add as a secondary group upto 15.
when you create a new user using useradd name that time in /etc/skell there is 3
file that /.bash_logout /.bash_profile /.bashrc coppied to the new user file & when
you logout the user /.bash_out file will excute & for login /.bash_profile
& /.bashrc file will excute
#etc/default/useradd - skell direct will visible & you can modify this file as you
want
#useradd -c "comment " username - for to add commnet while creating the user
/etc/passwd- stores username:X-password stored in shadow
file:UID:GID:commnent:/home-directory:/bin/bash
/etc/shadow- stores user password username:wjhdkjllwkqplpqwlsp-encrepted
passwd:passwd login date from 1970 to till date:how many time passwd change:maximum
paswwd change : passwd expire warning
/etc/group - stores username:group
#hostnamectl set-hostname - set hostname permanent
#dmidecode -s -for String keyword (for -s to check all the hardware related cmnd)
#grep filename /etc/paswd - to check password deatils
#chage -l username - to check policy of user
# which cmmnd - to check path of that cmmnd
#userdel for delete the user
#userdel -r username for delete user with respective directory
#groupadd for add group
#usermod -aG group username - for add in user to secondary group
#usermod -ag group usrname - for add user in primary group
#gpasswd -d username group - removing user from groups
#groupdel group name - to delete group
#useradd -d /directory/filename -u 1011 -c"comment" -m hp - for user creation with
customise.
for -m for mask, -c for comment, -u for uid.
#chown group:user: /directory/filename - for modify the user details 0r group
#chmod permission /directoy/username- for permision for that perticular
dir/filename
to change user directory #usermod -d directory to chnge user
without useradd commnd we can creating the user with the help of #vi /etc/passwd &
add the user parameters
create directory using mkdir -p /home/filename
#pwck - update pasword file
#pwconv - update group file
#grpck - update shadow file
than password chge the user using commnd paswwd username
#passwd -p username - for check status of user
#passwd -l lock
#passwd -u unlock
#passwd -d for remove pasword
#usermod -s for change the shell of the user
#chage -m 2 username(sajib) - for user cannot change paswd betwn 2days
#chage -E 12/31/2024 username for expire account
#chgrp groupname directory - to add directory in new group (fr ex: #chgrp sales
prod) sales is group & prod is directory.
#ls -ld - to check user details
To set the noexec option on the /dev/shm partition in Suse Linux, edit the
/etc/fstab file, locate the line for /dev/shm, and add noexec to the mount options,
then remount the partition.
Here's a step-by-step guide:
1. Open the /etc/fstab file:
Code
Permissions
chmod for change permission
chattr filename - if you apply the chattr coomnd to the file even root also not
can remove that file
#chattr +i filename to apply chattr
#chattr -i- to remove
USID is used for normal user can access the Sbin Commnd (special cmmnd)
#chmod u+s sbin commnd for normal user or #chmod 4770 /usr/sbin/fdisk (chmod u+s
/usr/sbin/fdisk - u is normal user, s is suid, /usr/sbin/fdisk is sbin cmmnd path)-
for apply usid
SETGUID
#chmod u-s sbin cmmd or chmod 0775 /usr/sbin/fdisk for remove usid
#chmod g+s , or chmod 277 directory/file- used to if sales is a group & 4to5 users
are there, if anyone can create the file the automatically the file of the group
become sales thats y we use cmmnd #chmod g+s /tmp/prod(g for group, s for guid,
dirctory )
for provide sudo permission for perticular sbin cmmnd for normal user we need to
add permission in the sudoers file - #vi /etc/sudoers
than in allow root to run any cmmnd - add user & ALL= commnd path (for ex.
/usr/sbin/fdi
sudo visudo
Comment out the line: # ALL ALL=(ALL) ALL. This line allows anyone to use sudo with
any command as any user, which is generally not desired. Add a # at the beginning
of the line to comment it out.
Uncomment the line: # %wheel ALL=(ALL) ALL. This line allows users in the wheel
group to use sudo with any command as any user. Remove the # at the beginning of
the line to uncomment it.
Save the file: Press Ctrl+X, then Y to save and exit.
3. Test sudo access:
Log out and log back in as the user you added to the wheel group.
Try running a command with sudo, for example: sudo ls -l /root.
You should be prompted for the user's password, not the root password.
To grant a user sudo privileges in Linux, add them to the sudo group using the
usermod command: sudo usermod -aG sudo <username>.
Here's a more detailed explanation:
Understanding sudo:
The sudo command allows users to execute commands with elevated privileges,
effectively acting as the root user for specific tasks.
The sudo group:
Most Linux distributions use a group called sudo to manage users who have sudo
privileges.
Adding a user to the sudo group:
Log in as a user with sudo privileges: You'll need to be logged in as a user who
already has sudo access to perform this action.
Use the usermod command:
Open a terminal.
Type the following command, replacing <username> with the actual username of the
user you want to grant sudo access to:
Code
groups alex
Switch to the user "alex" and try a sudo command:
Code
su - alex
sudo ls /root