Showing posts with label LINUX. Show all posts
Showing posts with label LINUX. Show all posts

Sunday, November 14, 2021

Linux: Delete Multiple Lines in VIM and Search for String in VIM

https://linuxize.com/post/vim-delete-line/

  • Press the Esc key to go to normal mode.
  • Place the cursor on the first line you want to delete.
  • Type 5dd and hit Enter to delete the next five lines.
----------------------------------------------------------------


The basic steps to perform a search in Vim are as follows:

  • Press /.
  • Type the search pattern.
  • Press Enter to perform the search.
  • Press n to find the next occurrence or N to find the previous occurrence.

Monday, October 18, 2021

Friday, September 24, 2021

Linux: Disk Handling Tool: Linux Disk Commands

lsblk -i
lsblk -f
df -Th 
du -sh * |sort -h

mount  /dev/sda  /data    [Manual]

mkfs.xfs /dev/sda
mkfs.ext4 /dev/sdb

edit FSTAB
/dev/sda /data ext4 defaults,nofail 0 0

mount -a

umount /dev/dsx
--------------------------------------------
DONT' UMount if its root disk
sudo parted /dev/sda
print
resizepart
resize2fs /dev/sda1
-------------------------------------------

Wednesday, August 4, 2021

GetEnt : Linux Commands

getent command in Linux with examples

getent is a Linux command that helps the user to get the entries in a number of important text files called databases

https://www.geeksforgeeks.org/getent-command-in-linux-with-examples/

Linux "Stat" Comand | OCTAL Permission

 stat - -format="%a" /path1/subdir


https://www.cyberciti.biz/faq/get-octal-file-permissions-from-command-line-on-linuxunix/

https://unix.stackexchange.com/questions/188674/how-to-get-file-permission-in-octal


To just see octal file permissions on a GNU/Linux:
$ stat -c '%a' /etc/passwd

linux "Id" Command

https://www.geeksforgeeks.org/id-command-in-linux-with-examples/

Linux: List of all Users and All Groups

  • getent passwd
  • getent passwd | cut -d: -f1


  • less /etc/group
  • getent group
  • getent group | cut -d: -f1


Linux : /etc/passwd vs /usr/bin/passwd (passwd Utility) vs /etc/shadow vs /etc/group

https://stackoverflow.com/questions/50904342/etc-passwd-vs-usr-bin-passwd


The two files are different, and serve different purpose.

  • /etc/passwd is user database (fun fact: contrary to its name, it doesn't store passwords - those are stored (possibly in hashed form) in /etc/shadow) - see man 5 passwd (i.e. passwd(5)), man 5 shadow (i.e. shadow(5)).


  • /usr/bin/passwd is utility that is supposed to modify user records stored in /etc/passwd and /etc/shadow. See man 1 passwd (i.e. passwd(1))

Linux : PAM : Pluggable Authentication Module

sudo pam_tally2 -u 703247699 --reset

Config Files for PAM
/etc/pam.d
/etc/security


sudo   pam_tally2   -u    userID123
---------------------------------------------------------
Login           Failures Latest failure     From
userID123    0





Linux - Special Dollar Sign Variables - $0, S1

https://stackoverflow.com/questions/5163144/what-are-the-special-dollar-sign-shell-variables

  • $1$2$3, ... are the positional parameters.
  • "$@" is an array-like construct of all positional parameters, {$1, $2, $3 ...}.
  • "$*" is the IFS expansion of all positional parameters, $1 $2 $3 ....
  • $# is the number of positional parameters.
  • $- current options set for the shell.
  • $$ pid of the current shell (not subshell).
  • $_ most recent parameter (or the abs path of the command to start the current shell immediately after startup).
  • $IFS is the (input) field separator.
  • $? is the most recent foreground pipeline exit status.
  • $! is the PID of the most recent background command.
  • $0 is the name of the shell or shell script.

Most of the above can be found under Special Parameters in the Bash Reference Manual. There are all the environment variables set by the shell.

For a comprehensive index, please see the Reference Manual Variable Index.


Tuesday, August 3, 2021

Linux : "sudo su userid" vs sudo "su userid -" ? What does dash mean - Login Shell vs Non Login Shell

https://askubuntu.com/questions/376199/sudo-su-vs-sudo-i-vs-sudo-bin-bash-when-does-it-matter-which-is-used


  • sudo su              interactive non-login shell. 

  • sudo su -           It is a login shell


To explain this you need to know what the programs do:

  • su - The command su is used to switch to another user (s witch u ser), but you can also switch to the root user by invoking the command with no parameter. su asks you for the password of the user to switch, after typing the password you switched to the user's environment.
  • sudo - sudo is meant to run a single command with root privileges. But unlike su it prompts you for the password of the current user. This user must be in the sudoers file (or a group that is in the sudoers file). By default, Ubuntu "remembers" your password for 15 minutes, so that you don't have to type your password every time.
  • bash - A text-interface to interact with the computer. It's important to understand the difference between login, non-login, interactive and non-interactive shells:

Types of shells:

  • login shell: A login shell logs you into the system as a specified user, necessary for this is a username and password. When you hit ctrl+alt+F1 to login into a virtual terminal you get after successful login a login shell.
  • non-login shell: A shell that is executed without logging in, necessary for this is a currently logged-in user. When you open a graphic terminal in gnome it is a non-login shell.
  • interactive shell: A shell (login or non-login) where you can interactively type or interrupt commands. For example a gnome terminal.
  • non-interactive shell: A (sub)shell that is probably run from an automated process. You will see neither input nor output.

So the cases are:

  • sudo su Calls sudo with the command su. Bash is called as interactive non-login shell. So bash only executes .bashrc. You can see that after switching to root you are still in the same directory:

    user@host:~$ sudo su
    root@host:/home/user#
    
  • sudo su - This time it is a login shell, so /etc/profile.profile and .bashrc are executed and you will find yourself in root's home directory with root's environment.

  • sudo -i It is nearly the same as sudo su - The -i (simulate initial login) option runs the shell specified by the password database entry of the target user as a login shell. This means that login-specific resource files such as .profile.bashrc or .login will be read and executed by the shell.

  • sudo /bin/bash This means that you call sudo with the command /bin/bash/bin/bash is started as non-login shell so all the dot-files are not executed, but bash itself reads .bashrc of the calling user. Your environment stays the same. Your home will not be root's home. So you are root, but in the environment of the calling user.

  • sudo -s reads the $SHELL variable and executes the content. If $SHELL contains /bin/bash it invokes sudo /bin/bash (see above).

Linux : SCP : without Password : With PEM File :Private key

scp -i mykey.pem somefile.txt root@my.ec2.id.amazonaws.com:/


https://stackoverflow.com/questions/6558080/scp-secure-copy-to-ec2-instance-without-password

Linux : What does the asterisk mean after a filename when you type `ls -l`?

https://superuser.com/questions/178786/what-does-the-asterisk-mean-after-a-filename-when-you-type-ls-l

Linux - SetUID - SetGID - Stick Bit - Special File Permissions

setgid Creates a file using owner rather than user creating it

setuid sets the permission of execution

sticky bits - Accidental Delete Protection Bit

https://www.cbtnuggets.com/blog/technology/system-admin/linux-file-permissions-understanding-setuid-setgid-and-the-sticky-bit   [IMP]

https://geek-university.com/linux/uid-user-identifier-gid-group-identifier/


Setting the setuid bit
To set the setuid bit symbolically, we can use chmod u+s </path/to/the/file>.
To set the setuid bit using octal representation we can add "4" to the front of our standard octal permissions


Setting the setgid bit
To set the setuid bit symbolically, we can use chmod g+s </path/to/the/file>.
To set the setgid bit using octal representation we can add "2" to the front of our standard octal permissions


Setting the sticky bit
We can set the sticky bit on directories symbolically with chmod +t :
Or using octal values and putting "1" in front of our standard permissions:

IPTables - Firewall -Linux - Redhat

https://www.redhat.com/sysadmin/iptables

Mongodb /etc/mongod.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 processManagement:

   fork: true

net:

   bindIp: localhost

   port: 27017

storage:

   dbPath: /var/lib/mongo

systemLog:

   destination: file

   path: "/var/log/mongodb/mongod.log"

   logAppend: true

storage:

   journal:

      enabled: true



Thursday, July 15, 2021

Linux Variables: Shell Variables: Local Variables : Environment Variables

 https://www.tutorialspoint.com/unix/unix-using-variables.htm

https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-set-environment-variables-in-linux/

export NAME=VALUE

export JAVA_HOME=/opt/openjdk11


unset VARIABLE_NAME

unset JAVA_HOME


::Listing All Set Environment Variables::

set


variable_name=variable_value

NAME="John Doe"

echo $NAME


readonly NAME


export NAME


Linux Variable Types

When a shell is running, three main types of variables are present −

Local Variables

Environment Variables 

Shell Variables 

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass