Tuesday, December 1, 2015

Linux Basic Commands

How to change Shell in Linux?


  1. cat /etc/shells (In that file you will see all shell that support by OS)
  2. To change Shell "chsh -s /bin/shell name" "chsh -s /bin/tcsh"
  3. Change Shell for user "chsh -s /bin/shell name Username" "chsh -s /bin/tcsh jiten"
What is the command to check user group name , group ID , UID ?
id username
id jiten (This command will show you UID , GID , group name)

What is the command to check user account expiry date info?
chage -l username
chage -l jiten (This command will show you user related information)

User add command options?
what is the command to create user in different directory?
useradd -d /home/directory name/ username   username
useradd -d /home/sale/jiten jiten

what is the command to user with specific user ID?
useradd -u UID number user name
useradd -u 2222 jiten

what is the command to user with specific GID?
useradd -u UID number -g GID number username
useradd -u 3323 -g 400 jiten
or 
useradd -g 391 jiten

what is the command to add user in multiple group?
useradd -G group name username
useradd -G postfix,sale,market jiten
(To separate groups we use "," sign )

what is the command  to add user without HOME directory?
useradd -M username
useradd -M jiten

what is the command to add user with  account expiry date?
useradd -e yyyy-mm-dd username 
useradd -e 2013-06-01 jiten

what is the command to set user expiry date and days?
useradd -e 2013-06-01 -f 45 (days) username
useradd -e 2013-06-01 -f 45 jiten  (user command with expiry in 45 days)

what is the command to set comment on user ?
useradd -c "Hello I am sales team" user name
useradd -c "Hello I am sales team" jiten

what is the command to change user shell?
useradd -s /sbin/nologin username
useradd -s /sbin/nologin jiten

Add user with specific Home directory , Default shell and Custom comment?
useradd -m -d /home/sales/username -s /bin/bash -c "sales person" -U username
useradd -m -d /home/sales/jiten -s /bin/bash -c "sales person" -U jiten 

Add user with home directory, custom shell , custom comment and UID/GID?
useradd -m -d /home/sales/username -s /bin/bash -c "hello" -u 6000 -g 6000 username
useradd -m -d /home/sales/jiten -s /bin/bash -c "hello" -u 6000 -g 6000 jiten

Add user with home directory , no shell , custom comment and UID?
useradd -m -d /home/sales/username -s /sbin/nologin -c "how are you team" -u 1020 username
useradd -m -d /home/sales/jiten -s /sbin/nologin -c "How are you team" -u 1020 jiten

Add user with home directory, shell,custom skell/comment and user ID?
useradd -m -d /home/sales/username -k /etc/custom.skell -s /sbin/tcsh -c "sales member" -u 3021 username
useradd -m -d /home/sales/jiten -k /etc/custom.skell -s /sbin/tcsh -c "sales member" -u 3021 jiten

Add user without home directory, No shell  and no group ?
useradd -M -N -r -s /bin/false username
useradd -M -N -r -s /bin/false jiten

What is the usermod command and it use ?

we use usermod command to modify user details
what is the command to change user home directory ?
usermod -d newdirectory name  olddirectoryname
usermod -d /home/testnet jiten (This command will not copy the content of jiten user directory to testnet directory)

what is the command to change user home directory with it content?
usermod -d newdirectory name -m olddirectory name
usermod -d /home/testnet -m jiten (When you will run this command it will copy jiten directory content to testnet directory)

what is the command to add group in user?
usermod -G group name user name
usermod -G developer jiten

what is the command to add group with exist group?
usermod -aG groupname username
usermod -aG developer jiten

what is the command to change user primary group?
usermod -g groupname username
usermod -g developer jiten
id username 
id jiten

what is the command to lock user?
usermod -L username
usermod -L jiten

what is the command to unlocking user?
usermod -U username 
usermod -U jiten

what is the command to change expiry date of user account?
usermod -e yyyy-mm-dd username
usermod -e 2016-12-30 jiten

what is the command to change login name ?
usermod -l newname username
usermod -l jitenjha jiten

what is the command to change login password?
usermod -p newpassword username
usermod -p newpassword jiten

what is the command to change user shell?
usermod -s /bin/bash username
usermod -s /bin/bash jiten


No comments: