lab1 from devops diploma on DEPI
sudo useradd -m -c "my name is Andrew Adel" -s /bin/bash -p $(openssl passwd -1 "Andrew") AndrewAdel
sudo: Runs the command with superuser privileges. useradd: The command to add a new user.
- -m: Creates a home directory for the new user.
- -c "Fullname/comment": Adds a comment (often used to store the full name of the user).
- -s /bin/bash: Specifies the user's login shell.
- -p $(openssl passwd -1 "password"): Sets the user's password. The openssl passwd -1 command hashes the password.
- username: The username for the new account.
- AndrewAdel: user name
cat /etc/passwd
sudo useradd -m -c "Bad User" -s /bin/bash -p $(openssl passwd -1 "baduser") baduser
sudo groupadd -g 30000 pgroup
- sudo: Runs the command with superuser privileges.
- groupadd: The command to add a new group.
- -g 30000: Specifies the GID for the new group.
- pgroup: The name of the new group.
cat /etc/groups
sudo groupadd -g badgroup
sudo usermod -aG pgroup islam
groups islam
id islam
sudo passwd islam
sudo chage -M 30 islam
sudo chage -l islam
sudo passwd -l baduser
- sudo: Runs the command with superuser privileges.
- passwd: The command used to change user passwords.
- -l: The option to lock the user account ||| -u: The option to unlock the user account
- baduser: The username of the account to be locked.
sudo userdel -r baduser
- sudo: Runs the command with superuser privileges.
- userdel: The command to delete a user account.
- -r: Removes the user's home directory and mail spool.
- baduser: The username of the account to be deleted.
sudo groupdel badgroup
- sudo: Runs the command with superuser privileges.
- groupdel: The command to delete a group.
- badgroup: The name of the group to be deleted.
sudo -i -u AndrewAdel
- sudo: Runs the command with superuser privileges.
- -i: runs the shell specified by the target user's default shell as a login shell
- -u: allow run a command as a specified user
11. Create a folder called myteam in your home directory and change its permissions to read only for the owner.
mkdir ~/myteam
chmod 400 ~/myteam
ls -ld ~/myteam
use the next to show all files and directories with their permission
ls -l
Change the permissions of oldpasswd file to give owner read and write permissions and for group write and execute and execute only for the others (using chmod in 2 different ways) change your default permissions to be as above.
chmod 631 oldpasswd
chmod u=rw,g=wx,o=x oldpasswd
to show:
ls -l oldpasswd
15. What is the maximum permission a file can have, by default when it is just created? And what is that for directory.
max permission
777 (read, write, and execute for owner, group, and others)
666 (read and write for owner, group, and others)
16. Change your default permissions to be no permission to everyone then create a directory and a file to verify
umask 777
mkdir dirNewMask
touch fileNewMask
umask
umask 002
umask
mkdir dirResetMask
touch fileResetMask
ls -ld dirNewMask
ls -ld dirResetMask
ls -ld fileNewMask
ls -ld fileResetMask
-
source direction: must be
- readable and excutable at least to be copied and listing its content
- and its content must be the same (readable and excutable if direction and readable if file)
-
target parent direction:
- must be excutable to be access it and allow changes
- must be writable to create new file or direction inside it
-
source file:
- readable
-
target parent direction
- must be excutable to be access it and allow changes
- must be writable to create new file or direction inside it
-
source file:
- no minimum permission requested for the file to be deleted
-
parent direction
- the parent direction must be writable and executable to delete file inside it
need the directiory to be executable
need the directory to be executable and readable
the file need to be readable
-
file:
- file must be writable
-
parent directory
- must be executable
run file like program or script
allows you to enter the directory and access its contents.
20. Using vi write your CV in the file mycv. Your CV should include your name, age, school, college, experience
:set number // show all lines number
/Age //Search for word age
5G //Step to line 5 (assuming that you are in line 1 and file is more than 5 lines).
dd // Delete the line you are on.
cat /etc/shells
env
// or
printenv
env | grep BASH_
echo $Variable
\\Example:
echo $SHELL
echo $0
- Initialization files are scripts that are executed automatically when a shell starts up.
- set environment variables
- define functions
- perform other setup tasks
- This file is located in the user's home directory ($HOME/.profile).
- It is executed when a login shell starts.
- Example: /home/user/.profile
- This file is also located in the user's home directory ($HOME/.shrc).
- It is executed when a non-login interactive shell starts.
- Example: /home/user/.shrc
- Similar to sh, the .profile file in the user's home directory ($HOME/.profile) is executed when a login shell starts.
- Example: /home/user/.profile
- The .kshrc file in the user's home directory ($HOME/.kshrc) is executed when a non-login interactive shell starts.
- Example: /home/user/.kshrc
- .bash_profile, .bash_login, or .profile
- bash looks for these files in the following order: .bash_profile, .bash_login, and .profile.
- It executes the first one it finds in the user's home directory ($HOME).
- Example:
/home/user/.bash_profile
,/home/user/.bash_login
, or/home/user/.profile
- The
.bashrc
file in the user's home directory ($HOME/.bashrc) is executed when a non-login interactive shell starts. - Example: /home/user/.bashrc
add the following code into ~/.profile file
# Display date at login
echo "Today's date: $(date)"
# Customize prompt
export PS1="\[\e[36m\]\u@\h \[\e[33m\]\w\[\e[0m\] $ "
save it and execute the file using source:
source ~/.profile
- indicating that the command continues on the next line.
The prompt > that appears is called the PS2 prompt, which indicates that the shell is expecting more input to complete the command.
export PS2=": "