Sunday 5 July 2020

How do you set Linux file/directory permissions?


126. How do you set Linux file/directory permissions?

To set file permissions, use the chmod command followed by the octal value or symbolic value then the file name or directory name.

For example to assign a file permissions value of 664 run
chmod 664 filename

To assign directory permissions, use the -R option to assign permissions recursively.
chmod -R 664 directory_name.

127. How to set ownership for files/directories?

To set file owner use the chown command. 
For example, 
chown user:user filename.

For a directory use the -R option to assign permissions recursively. 
For example,
chown -R user:user directory_name

128. What is swappiness in Linux?

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.

Swappiness can be set to values between 0 and 100.

vm.swappiness = 0   # Swap is disabled. In earlier versions, this meant that the kernel would swap only to avoid an out of memory condition, but in later versions this is achieved by setting to 1.

vm.swappiness = 1   # Kernel version 3.5 and over, as well as kernel version 2.6.32-303 and over: Minimum amount of swapping without disabling it entirely.

vm.swappiness = 10  # This value is sometimes recommended to improve performance when sufficient memory exists in a system, this value *10* could be considered for the performance being expected. 

vm.swappiness = 60  # The default value.

vm.swappiness = 100 # The kernel will swap aggressively.

129. How to configure the swappiness parameter to improve overall performance?

The Linux kernel provides a tweakable setting that controls swappiness,
$ cat /proc/sys/vm/swappiness
60  

For example, open /etc/sysctl.conf as root. Then, change or add this line to the file:
vm.swappiness = 10

for changing the swappiness value temporarily try this command:
$ echo 50 > /proc/sys/vm/swappiness

130. How can you append one file to another in Linux?

To append one file to another in Linux you can use command cat file2 >> file 1. The operator >> appends the output of the named file or creates the file if it is not created. While another command cat file 1 file 2 > file 3 appends two or more files to one.

131. What is NFS and Benefits of NFS?

Full form of NFS is Network File System. NFS is used for sharing of the files and folders between Linux/Unix systems by Sun Microsystems in late 1980. NFS helps you in mounting your local file systems or drive over a network and remote \ client hosts can use it as it mounted locally on their system. With the help of the NFS, we can set up file sharing between the cross-operating system, Unix to Linux system and vice versa. If you want to use Linux system mount on windows, you need to use SAMBA\CIFS in place of NFS.

Benefits of NFS:-

You can access remote files as local
NFS uses client/server architecture for file sharing
NFS support file sharing cross-operating systems
NFS helps in building centralized storage solutions
Users can access their data irrespective of physical location
No manual refresh needed for new files
NFS can be secured with Firewalls and Kerberos

132. Which command will list the current time source?

The ntpd program is an operating system daemon which sets and maintains the system time of day in synchronism with Internet standard time servers.
# ntpd -q

133. Name some of the text editors that are available in Linux ?

Some of the common text editors that are available in Linux are vi/vim, nano, subl, gedit, atom, emacs. Vi is the default editor that you have in Linux machines.

134. How to check on the status of our RAID device?

# mdadm –query –detail /dev/md0
# cat /proc/mdstat

135. Find Files Without 777 Permissions?

# find / -type f ! -perm 777

136. What is the command to find all the files and directories having 777 permissions ?

find –perm option is used to find files based on permissions
Here "." or period denotes the current directory
$ find . -perm 777

137. How to find the difference in two configuration files?

You can use the diff command for this: 
$ diff abc.conf xyz.conf

138. What are the modes used in VI editor?

There are 3 types of modes in vi Editor:
Regular mode or command mode
Insertion mode or edit mode
Replacement mode or Ex mode

139. How to check os version in Linux command line ?

Type any one of the following command to find os name and version in Linux:
$ cat /etc/os-release
$ lsb_release -a 
$ hostnamectl
$ uname -r

140. How to find the kernel/OS version in Linux?

Run the command,
$ uname –a

141. How to get +100 MB files in file system?

$ find / -type  f -size +100M

142. What is the use of scp command in linux ?

SCP command stands for secure copy. It is used to copy/download data from one machine to another machine.

143. What is a jump server ?

A jump server is a virtual machine that is used to manage other systems. It is sometimes called a “pivot server” for this reason: once you are logged in, you can “pivot” to the other servers. It is usually security hardened and treated as the single entryway to a server group from within your security zone, or inside the overall network. A jump server is a “bridge” between two trusted networks. The two security zones are dissimilar but both are controlled.

144. What is a bastion host ?

A bastion host is also treated with special security considerations and connects to a secure zone (also known as jump server), but it sits outside of your network security zone. The bastion host is intended to provide access to a private network from external networks such as the public internet. Email servers, web servers, security honeypots, DNS servers, FTP servers, VPNs, firewalls, and security appliances are sometimes considered bastion hosts.

145. How to reverse lookup for IP address?

$ dig -x IP-Address

146. Getting rid of “-bash: dig: command not found” ?

install bind-utils package. It contains a collection of utilities (such as dig command and other) for querying DNS name servers to find out information about internet hosts. These tools will provide you with the IP addresses for given host names, as well as other information about registered domains and network addresses.

Use the yum command to install dig on CentoS 7:
$ sudo yum install bind-utils

147. Explain dig command output?

The dig command output has the following sections:

HEADER: This displays the dig command version number, the global options used by the dig command, and few additional header information.

QUESTION SECTION: This displays the question it asked the DNS. i.e This is your input. Since we said ‘dig redhat.com’, and the default type dig command uses is A record, it indicates in this section that we asked for the A record of the redhat.com website.

ANSWER SECTION: This displays the answer it receives from the DNS. i.e This is your output. This displays the A record of redhat.com.

AUTHORITY SECTION: This displays the DNS name server that has the authority to respond to this query. Basically this displays available name servers of redhat.com.

ADDITIONAL SECTION: This displays the ip address of the name servers listed in the AUTHORITY SECTION.

STATUS SECTION: Stats section at the bottom displays few dig command statistics including how much time it took to execute this query.

148. How do I use dig command?

The syntax is:

dig Hostname
dig DomaiNameHere
dig @DNS-server-name Hostname
dig @DNS-server-name IPAddress
dig @DNS-server-name Hostname|IPAddress type

149. Sometimes NSCD die itself and DNS resolving doesn't occur properly. How can we avoid NSCD for DNS and is there any disadvantage to bypass it?

NSCD means Name Service Cache Daemon which provides a cache for the most common name service requests. When resolving a user, group, service the process will first try to connect to the NSCD socket (something like /var/run/nscd/socket2).

If NSCD died, then the connection will fail and NSCD won't be used for same and that should not be a problem.

If NSCD in a hung state, then the connection may hang or succeed. If this succeeds then the client will send the request. Now, we can configure NSCD to disable caching for any type of the database (for instance by having enable-cache hosts no in the /etc/nscd.conf for hosts database).

However, if NSCD is in a hung state, it may not be able to even give that simply won't do the answer, so that won't necessarily help. NSCD is a caching daemon, it's meant to improve the performance. Disabling it would potentially make those lookups slower. However, that's only true for some kind of databases. For the instance, if user/service/group databases are only in small files (/etc/passwd, /etc/group, /etc/services), then using NSCD for those will probably bring little benefit if any. NSCD will be very useful for the host's database.

150. What are aliases and how to create them with examples ?

Aliases are abbreviated shortcuts used to represent a command or a group of commands executed with or without custom options.
alias command instructs the shell to replace one string with another string while executing the commands.

#Alias for log directory
alias logs="cd /user/application/logs"

These aliases can be put in the ~/.bash_aliases file.

To have the aliased command on any existing terminal, user needs to source ~/.bashrc from the terminal :
source ~/.bashrc

                                                                                           MENU         PREVIOUS | NEXT

No comments:

Post a Comment