Miscellaneous Commands -1

Super User & File Permissions

Linux Users

The root user, also known as the superuser or administrator, has access to all commands and files.

Root User

sudo
command temporarily elevates the privileges allowing users to complete sensitive tasks without logging in as the root user.

sudo command

Linux Commands

Executable Path

which
command is used to identify the location of a given executable path.

Syntax :

which command

Example :

$ which sudo
/usr/bin/sudo

Create New Users

useradd
is used to create a new user with the given username.

Syntax :

sudo useradd username

Example :

sudo useradd abhi

Set/Change User Password

passwd
is used to set or change password of a given user.

Syntax :

sudo passwd username

Example :

sudo passwd abhi

Execute Command as Another User

su
is used to execute command as another user.

su user
su -c command user

File Permissions

Authorization Levels

Multi-user operating systems like linux provide two levels of authorization in securing the files

  • Ownership

  • Permission

User Ownership

Users accessing a file/ directory can be categorized into 3 types

TypeDescription
OwnerUser who is considered as owner
GroupA group of users, who are assigned a specific permission
OthersAny other users who doesn’t belong to the above two types

Ownership and Permissions

PermissionsDescription
ReadOpen and read a file
WriteModify the contents of a file
ExecuteAuthority to run as a program

File Permissions in Linux

Changing Permissions

Syntax :

chmod permissions filename

Example :

chmod 764 sample.txt

"chmod" stands for change mode

NumberBinarySymbolPermission Type
0000---No Permission
1001--xExecute
2010-w-Write
3011-wxExecute + Write
4100r--Read
5101r-xRead + Execute
6110rw-Read +Write
7111rwxRead + Write +Execute

Changing Ownership

  • For changing the user of a file/directory

Syntax :

sudo chown user filename

Example :

sudo chown root sample.txt
  • For changing the user and group of a file/directory

Syntax :

sudo chown user:group filename

Example :

sudo chown root:root sample.txt

Packaging

Package & Repository

  • A package file is a compressed collection of files that comprise the software package

  • Packages are stored in repositories to make them accessible to users

Package Managers

apt

  • APT stands for the Advanced Packaging Tool

  • It is used to install, upgrade or remove software packages in linux

Syntax :

sudo apt

Installing Package

Installing a package from a repository

Syntax :

sudo apt install package_name

brew

  • It is a Package Manager for macOS.

    • With 
      brew
       command you can install the packages in macOS.

Installing Package

Syntax :

brew install package_name

yum

yum
is a graphical based package management tool for RPM (RedHat Package Manager) based Linux systems.

Installing Package

Syntax :

yum package_name

Downloading Files From Web

wget

wget
is a command-line utility for downloading files from the web.

To install

wget
:

  • apt
sudo apt install wget
  • brew :
sudo brew install wget
  • yum:
sudo yum install wget

wget
will download the resource specified in the url to the current directory.

Syntax :

wget "URL"

Example :

wget "https://www.lifewire.com/uses-of-command-wget-2201085"

curl

curl
is a command-line utility for transferring data from or to a server designed to work without user interaction.

To install

curl
:

  • apt:
sudo apt install curl
  • brew :
sudo brew install curl
  • yum :
sudo yum install curl

curl
prints the contents of the URL to the output.

Syntax :

curl "URL"

Example :

curl "wttr.in"

Searching a Package

apt-cache
command is used to searches for a particular package.

Syntax :

sudo apt-cache search package_name

Example :

apt-cache search google

Updating Packages

  • System checks against the repositories.

  • If newer version available of the program it will update the information about the existing packages and their versions available.

Updating a package from a repository:

upgrade

upgrade
will upgrade all the applications to latest version.

sudo apt upgrade

update

update
will simply update the information about the existing packages and their versions available

sudo apt update

Listing Installed Packages

dpkg -l
: It is used to list all installed packages

sudo dpkg -l

Adding Repository

PPA (Personal Package Archive) is an application repository that can be used to upgrade and install packages from third parties.

add-apt-repository
: It is used to add repository

Syntax :

sudo add-apt-repository repository_link

Adding the Private PPA's security key

Your Linux device can use that signature to check the authenticity of the packages.

apt-key
: Add PPA security key

Syntax :

sudo apt-key add - KEY_ID

Removing a Package

remove
: removes the installed packages

Syntax :

sudo apt remove package_name

Summary

CommandDescription
sudoTemporarily elevates the privileges
whichUsed to identify the location of a given executable path
useraddUsed to create a new user with the given username
passwdUsed to set or change password of a given user
suUsed to execute command as another user
chmodUsed to change the access permissions of file
chownChanging the user of a file/directory
aptUsed to install, upgrade or remove software packages in linux
wgetUsed for downloading files from the web
curlUsed for transferring data from or to a server
apt-cacheSearches for a particular package
add-apt-repositoryUsed to add repository
apt-keyUsed to add PPA security key
Warning

Under the installation of an

apt
package from a PPA, there is a change in one of the MongoDB installation steps, due to the changes made by the MongoDB website.

Update command from

curl https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

to

curl https://pgp.mongodb.com/server-4.4.asc | sudo apt-key add -

for a seamless monogodb installation.

Post a Comment

Please Select Embedded Mode To Show The Comment System.*

Previous Post Next Post

Contact Form