Understanding Linux File Permissions and Ownerships

Image
From one of our previous articles "How to manage Linux Users and Groups" we discussed on how Linux becomes a multi-user OS, what is a user and a group with their configurations. By design, even though Linux allows multiple users can use the same computer in the same time without affecting others, Linux doesn't allow you to access or modify files belonging to other users. If Linux allows you to do it, that would be a security risk. But somehow they have implemented a security measure to mitigate that security risk. With that we can make sure only desired users and groups can access the relevant files and directories.

If we take a small demonstration. Here, we will log in as a normal user and try to access a root directory.


It gave a permission denied error when accessing. Why ? That's because /root directory is owned by user root. Only a privileged user can access or modify that.

So, Linux introduces two kind of factors which tells who can access or modify a file as w…

What is an alias in Linux ?


In the previous article we learned few very basic commands like pwd, ls , cd, vim, touch, cat, less and more. We could learn there are options we can use with the commands like options used with ls command in the previous article.

So, normally we have to use these Linux custom commands frequently. Typing the same command over and over reduces the productivity. Because of that reason we use aliases. What alias do ? It's like a custom shortcut to represent a command or a set of commands.

Eg : Without typing ls -lrt every time, we  can create an alias in one or two characters to represent that command.

1) To view current aliases that have created. 

$ alias

What is an alias in Linux operating system ? How to make a permanent alias ?


2) How to create an alias ?

Below is the syntax,

alias <shourtcut name> ="Your custom command"

eg :
alias t="ls -lrt" ( We can use "t" to list files sorted by time )
alias h="ls -lh" ( We can use "h" to list files sorted by file size )
alias sshx="ssh student@serverx" ( We can use sshx for connecting to serverx with ssh )

* But, above aliases are not permanent. They are active within that user login time. If the user signed out, those aliases will be erased and only permanent aliases will be shown. 

3) How to create a alias permanent ?

There is a file named "bashrc" ( a hidden file ) in your home directory. It will be appear as
~/.bashrc

bashrc file is a shell configuration files. This file will be run in each time of a shell interaction session.

4) What is a shell ?

 Shell is a program given to users for interaction with the system. Simply an interpreter that executes commands reading from standard input keyboard or from a file. There are different types of shells in Linux.

  • Bash shell
  • C shell
  • korn shell
You can find your running shell with this command

env | grep SHELL

So, in order to make an alias permanent we need to put them in bashrc file in user home directory. 

vi ~/.bashrc ( Open the bashrc file for editing )
alias ll="ls -l" ( write the alias inside of the file and save it )

Logout from your account and login back. Check the alias, now your alias is permanent for your account. 

* In order to make an alias permanent for all the users in your linux OS, you must create a file in /etc/profile.d directory with a name for your alias. Then edit that file and write the normal alias that we wrote in the above. After that logout from the account and log in back. Check, your alias will be in all the accounts. But remember /etc/profile.d is directory with root permissions ( simply only root can edit those files ). So to change that you either need to be the root or you should be a super user. 

Cheers!


Comments

Popular posts from this blog

Different types of users in linux

SUDO: What is it in Linux ?

Linux Commands Tips and Tricks