Ubuntu codes and behave of its reasons

I would Like to share some basic commands for Ubuntu.I will update more commands on my future blogs.

Ubuntu commands
Command          Reason
ping This is a utility used to verify whether network data packet is capable of being distributed to an address without errors.
tar xvzf package.tar.gz                    To extract the files
sudo su Go to root privilage
pwd See the path.
touch to create new file.
mkdir to create new directory.
vi to open the file through VIM editor
cd to change the path
php x.php to run the php file on terminal
systemctl status network Check the network.service status

User Management

  • Every process (running program) on the system running for particular user.Every file is owned by a particular user.
arebhy@arebhy-Aspire-5742:~$ ps aux
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.1 185508  6196 ?        Ss   12:22   0:01 /sbin/init spla
root         2  0.0  0.0      0     0 ?        S    12:22   0:00 [kthreadd]
root         4  0.0  0.0      0     0 ?        S<   12:22   0:00 [kworker/0:0H]
root         6  0.0  0.0      0     0 ?        S<   12:22   0:00 [mm_percpu_wq]
root         7  0.0  0.0      0     0 ?        S    12:22   0:00 [ksoftirqd/0]
root         8  0.0  0.0      0     0 ?        S    12:22   0:01 [rcu_sched]
root         9  0.0  0.0      0     0 ?        S    12:22   0:00 [rcu_bh]
root        10  0.0  0.0      0     0 ?        S    12:22   0:00 [migration/0]
First column shows the user name.
  •  To view the user associated with a file directory associated with permission
arebhy@arebhy-Aspire-5742:~$ ls -l
total 12
drwxrwxrwx  10 arebhy arebhy      4096 පෙබ  27 10:30 app
-rwxr-xr-x   1 arebhy arebhy   1861877 මාර්   9 15:23 composer.phar
drwxrwxrwx   8 arebhy arebhy      4096 මාර්  27 23:07 Desktop
drwxrwxrwx   2 arebhy arebhy      4096 පෙබ  20 13:07 Documents
drwxrwxrwx  22 arebhy arebhy     12288 අප්‍රි   3 12:48 Downloads
-rwxrwxrwx   1 arebhy arebhy      8980 පෙබ  20 12:23 examples.desktop
-rw-rw-r--   1 arebhy arebhy    156340 මාර්  20 13:48 final.xlsx
-rw-rw-r--   1 arebhy arebhy   1888973 මාර්  20 12:41 final.xml
-rwxrwxrwx   1 arebhy arebhy      1880 පෙබ  27 10:30 Gemfile
-rwxrwxrwx   1 arebhy arebhy      4367 පෙබ  27 10:30 Gemfile.lock
drwxrwxr-x  13 arebhy arebhy      4096 මාර්   5 12:05 genieacs-gui
-rwxrwxr-x   1 arebhy arebhy       829 මාර්   5 12:04 genieacs-start.sh

Create User
  • Every user have group and every user have userid(uid) and groupid(gid).
  • To manage user you need to be a root privilege.
arebhy@arebhy-Aspire-5742:~# sudo su
arebhy@arebhy-Aspire-5742:~# groupadd --gid 1000 bob
arebhy@arebhy-Aspire-5742:~# useradd --uid 1000 --gid 1000 --home-dir /home/bob -m bob
  • Add a new user from same group id
arebhy@arebhy-Aspire-5742:~# usermod -aG bob alice passwd bob
  • To see existing group id
arebhy@arebhy-Aspire-5742:~#vim /etc/group 

Delete the user

arebhy@arebhy-Aspire-5742:~#userdel bob

UGO (User,Group,Other) Concept

Access to files by users are controlled by file permissions.The Linux file permissions system is symle but flexible.

Files have just three categories of user to which permission apply.This file is owned by user,normally the one who created the file.
The file is also owned by a single group, usually he primary group of the user who created the file, but this can be changed.
Different permissions can be set for the owning user,he owning group, and for all others users on the system that are not the user or a member of the owning group.

There are three kinds of permissions can apply:
  1. READ
  2. WRITE
  3. EXECUTABLE
Permissions
Permission Effect on filesEffect on directories
r(read)Contents of the file can be read Contents of the directories(file name) can be listed
w(write) Contents of the file can be changedAny file in the directorates may be created or deleted
x(exec)Files can be executed as commandsContents of the directory can be accessed(dependent on the permissions of the files in the directories)

for more details
https://www.guru99.com/file-permissions.html

Model Questions




Managing Permission from the command line

Symbolic method keywords;
chmod whowhatwhich file|directories 
  • Who    -  u,g,o,a( for user,group,other,all)
  • What   -  +,-,= (for add,remove,set exactly)
  • Which -  r,w,x (for read,write,executable)
Numeric Method:
arebhy@arebhy-Aspire-5742:~#chmod ### file|directories 
Each digit represent an access level:user,group,other
# is sum of r=4,w=2 and x=1

Example:
arebhy@arebhy-Aspire-5742:~#chmod go-rw file|directories 

arebhy@arebhy-Aspire-5742:~#chmod a+x file|directories 

arebhy@arebhy-Aspire-5742:~#chmod 750 file|directories 

Change root passwd
  • press Ctrl + Alt + T to open terminal
  • then type su
  • it ask your password then enter your password
  • if you see the error msg like "su: Authentication failure"
  • then check your user name by this command "whoami"
  • then type " sudo passwd root " it will help to change your password
 Screenshot from 2017-07-05 19-39-08


Comments

Popular posts from this blog

Easy understanding of MVC design architecture

A / B Testing

Firewall