Lnx Flashcards

1
Q

Remote command execution

Linux: How to run a command on a remote machine.

A

Use ssh,

> ssh  laeeq@192.168.0.49    ls  /tmp
> ssh  laeeq@192.168.0.49    date

you may have to give absolute path of the command you want to execute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to find state of a port (3000)?

A
> sudo  lsof  -i:9950               # Linux
> netstat  -an | grep 9550      # Linux
> netstat -an | find  /I "9550"  # Windows
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

tcpdump

What is tcpdump command to get traffic to/from port 3000

A
>  tcpdump -i any port 3000
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

vimdiff

What are vimdiff commands?

A
  • CTL-ww swhitches windows
  • do: diff obtain, get difference from other window
  • dp: diff put: send difference to other window
  • ]c: go to next diff
  • [c: go to previous diff
  • zo: open zip
  • zc: close zip
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

core file

How to force core file generation from a crashing program.

A
> ulimit   -c  unlimited
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to display current resource limits for a user?

A
> ulimit    -a
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

gdb

How to set a conditional break point in gdb.

A
b  fileName.c:56  if x==50
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Dangling symbolic links

What happens when you delete a symbolic link.

A

The target or actual file remains unaffected.
However, if u delete the target, the symbolic link continues to point to non-existing target file (this called dangling/orphaned symbolic links).

Soft link = Symbolic link

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what does the tee command do?

A

tee cmd is used to copy the output of a command to a file.

In addition to displaying normal output of the command, the output is also written to a file.

It is used with pipe symbol

> wc -l   prog.c   |   tee    file1.txt

to append to a file instead of overwriting,

> wc -l  prog.c   |   tee -a   file1.txt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is HereDocument used?

A

When a large amount of textual multiline data is needed as argument to a command, we can use Here Docuement and provide data inside shell script itself, rather than providing data in a file.

cat << ABCD
line 1111
line 222
line 333
ABCD
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Pass envirenment variable to a script

How to make a variable available inside a shell script?

A
> TARGET=x86       ./script.sh

Value of TARGET will be available inside script.sh

Assign values to env variables just before calling the script on the same line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to read a variable inside a shell script from keyboard?

A

Use read command,

read    variableName
echo    $variableName
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a common usage of xargs?

A

When a command generates a list of files, such as find command. We can make this file list available to another command like grep or rm etc, so that these commands can work on the files list generated by the first command.

Following can be used to delete all header files found by cmd find

> find   .   -name   "*.h"  |  xargs  rm  -v

args is normally used after a pipe symbol

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Errors in make file recipes

In make file what happens when an error occurs at any time?

A

Default behaviour: Make program is aborts immediately, no further commands are executed.

If you pre-append minus sign ‘-‘ to any command, error in that command will be ignored and next command will be executed.

If you pre-append ‘@’ to any command, make will not print that command before executing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are common automatic variables in makefiles?

A
  • $@ : Name of current target.
  • $^ : List of all dependencies
  • $< : First dependency in the list of dependencies.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

gdb: How to get the sequence of function calls leading to current point of execution?

A
bt
backtrace

Each stack frame will have a number associated with it. Top most stack frame is the most recent one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

gdb: How to get the local variables in current function?

A
info  locals
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Command line editing: Go to begining of line.

A
CTL  a

a = begining

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Command line editing: Go to end of line.

A
CTL  e

e = end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Command line editing

Command line editing: Delete from curser positionn to the end of line?

A
CTL  k

k = Kill

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Command line editing

Command line editing: Clear the whole current line

A
CTL ak

ak = All Kill

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

iptables: name three chains

A

INPUT chain, OUTPUT chain, FORWARD chain

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is an iptables policy?

A

Each chain has a policy, ACCEPT or DROP.

ACCEPT: Allow all pkts unless a specific rule forbids that kind of pkt.

DROP: Disallow all pkts unless a specific rule allows that kind of pkt.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What are primary and secondary groups in Linux?

A

Primary group: Has the same name as user name. Created at the time when user is created. Newly created user has membership of this group immediately.

Secondary group: Other groups created separately. Users need to be made members of secondary groups explictly using cmd gpasswd

> gpasswd     groupName    -a     userName
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Linux user groups

How to find to which groups a user belongs to?

A
>  groups         laeeq
>  groups           # will give info about current user.

You can also use,

~~~
> id laeeq
> id # Lists groups which logged in user is member of
```

You can also read /etc/group file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Which file contains group information

A

/etc/group

27
Q

How to create a new group in Linux?

A

addgroup newGroupName

Verify using cat /etc/group

28
Q

Add a user to a Linux group

How to make user1 a member of group1

A

Use command gpasswd

gpasswd group1 -a user1

You can also use usermod command.

29
Q

Revoke the membership from a group

How to remove a user from a group?

User will no longer have that group’s permissions

A

gpasswd groupName -d userName

Verify using groups userName

30
Q

Linux user groups

How to modify a groups details, like change group name etc.

A

Use command
groupmod

Modify group

31
Q

How is the owner group of a file determined?

A

Owner group of a file is the primary group of the user who created the file

32
Q

Linux gropus

What are system & non-system of groups in Linux?

A

There are two kind of groups,

  1. non-system groups
  2. system gropus

Non-system groups are used for managing user permissions and access.
System groups are used by system services & daemons to allow system processes to share access to resources, files, directories etc.

33
Q

system groups

How to create a system group in Linux?

A
addgroup  newGroupName   --system

Normally group id (gid) is less then 1000 for these groups

34
Q

Linux system users

How to create a system user?

A
> adduser    newUserName    --system

  • Normally UID of system users is less than 1000.
  • They may not have home dir.
  • They may not have human login capability.
35
Q

Linux directory permissions

How to interpret the permissions of a directory as opposed to a file?

as opposed to a permissions of a file.

A
  • read: Ability to list dir contents
  • write: Ability to create/delete files in this dir.
  • execute: Ability to cd into this dir.
36
Q

setuid

What is the purpose of setuid on an executable file?

A

When you set the setuid on an executable file, then when that file is executed by a non-owner user, the resulting process will still have all permissions of the real owner of that file. Even though the real owner did not run that program.

-rwS
Capital S means, original file did not have execute permission.
lower case s means, original file had execute permission too.

37
Q

How to set sticky bit on a file?

A
chmod  +t  fileName

other’s permission will become –T

38
Q

Linux groups

How to change the owner group of a file?

A

Use chgrp command

> chgrp     groupName      fileName
39
Q

Linux groups

How to change the owner group of a file?

A

Use chgrp command,

chgrp    groupName    fileName
40
Q

C++ scoped enum

What are scoped enums in C++

A

Define like this,

enum class Fruit
{
banana,
apple,
};

Fruit  frt;
frt  =  Fruit::apple;
41
Q

What is the benefit of curly brace initialization of variables, like
~~~
int x{10};

// Rather than,
int x = 10;

// or
int x(10);
~~~

A

Compiler enforces exact type match.

int x = 5.1;  // works
int y(6.2);  // works
// but
int  z{7.3};  // compilation error

A conversion from floating point to integer is not done at initialization.

42
Q

Ubuntu packages

How to list all ubuntu packages?

A
> apt   list   
> apt    list   --installed

Use grep for specific pkg

43
Q

How to un-install an ubuntu package?

A
> apt  remove  pwgen  # Does not remove config files
>  apt  purge  pwgen  # Removes all config files
44
Q

How to remove unnecessary dependencies from Ubuntu?

A
> apt  autoremove
45
Q

How to check if a specific pkg is installed on ubuntu system?

A
> apt   search   pwgen

If it is insalled, it will show [installed]

46
Q

How to autoclean old downloaded archive files in ubuntu?

A
>  apt   autoclean
47
Q

How to get information about an ubuntu package?

A
> apt   show   pwgen

Does not show if a pkg is installed. Use apt list pwgen for that.

48
Q

Does each ubuntu release have a codename?

A

Yes, use following command,

> lsb_release   -a

Examples are jammy, Bionic Bever, Focal Fossa etc.

49
Q

How to create netcat chat between two computers?

A

Create listner/server

> nc  -l  -p 1299      # -l for listen,  -p port num

Create netcat client,

>  nc  192.168.1.100    1299    # dont use -p on listener
50
Q

How to check if a port is open on a machine using telnet

A
> telnet  192.168.1.100   22
  • connected to 192.168.1.100 ==> Open
  • Trying 192.168.1.100…… ==> Not open

More examples,

> telnet       google.com       443

  • telnet google.com 443
51
Q

On Redhat Linux, how to get info about package groups

A
> dnf   group   list
> dnf   group   list   --hidden
> dnf   group   list   --installed
52
Q

How to install Development Tools in RHEL?

A
>  dnf  groupinstall  "Development Tools"
53
Q

In Redhat linux, how to get info about a package group?

A
> dnf  group  info  "Development Tools"
54
Q

How to check the status of network manager?

A
> systemctl   status  NetworkManager
> nmcli   general

Do double tab after each part to see options available

55
Q

How to get info about NICs?

A
> nmcli    device    status
> nmcli    device    show
> nmcli    device    show   eth0

> nmcli   connection   show
> nmcli   connection   show   eth0
56
Q

How to easily create a new network profile in Linux.

A
  • Go to network settings (Wired)
  • Locate the interface name you want to use, press +
  • Add details such as DNS etc.
  • To activate new profile, disconnect networking, and connect using new profile.
57
Q

What are the major components of a connection profile?

A
  • interface name (eth0, enp3s0)
  • profile name (user defined text)
  • Type (ethernet, wireless)
  • IP4 address
  • subnet mask
  • Default gateway (gw4)
  • DNS addresses
58
Q

How to create a connection profile using nmcli command?

A
> nmcli connection add type ethernet ifname eth0 con-name my_new_conn ip4 192.168.1.111/24 gw4 192.168j.1.1

Specify following parameters,
* connection type (ethernet / radio)
* NIC name (eth0, enp7s0)
* New profile name (my_new_conn)
* ip4 (192.168.1.111/24)
* Default gateway (192.168.1.1)

59
Q

How to activate an already created connection profile?

A
> nmcli   connection  up   my_conn_profile_1  
60
Q

How to de-activate an active connection profile?

A
> nmcli   connection  down   my_conn_profile_1  
61
Q

How do you modify the parameters of a network profile?

e.g., add a DNS address.

A
> nmcli  connection  modify my_connection  ipv4.dns  "8.8.8.8  8.8.4.4"

>  nmcli  connection  modify  my_connection ipv4.address  "192.168.1.100/24" 

>  nmcli  connection  modify  my_connection ipv4.gateway  "192.168.1.1"

Take network profile down and up again to take effect.

62
Q

How to make output of nmcli cmd more readable?

A

Use -p pretty option,

nmcli   -p   connetion  show

Use -p with all nmcli operations.

63
Q

How to restrict a network profile usage to a set of users?

A
> nmcli  con  mod  my_connection  connection.permissions  mujid 

> nmcli  con  mod  my_connection  connection.permissions  user:mujid,farooq
64
Q

How do you delete a network/connection profile?

A
> nmcli  connection delete my_connection_profile

Use nmcli connection show to list all known connections/profiles.