Sunday, 5 July 2020

Explain the usage of curl command in Linux?


226. Explain the usage of curl command in Linux ?

In Linux, Curl command is a tool to transfer data from or to a server. In Linux, curl command is used to test an application's endpoint or connectivity to an upstream service endpoint. It is used to determine if the application can reach another service, like a database, or to check if the service is up and running . This  command doesn’t require any user interaction.

Example:
$ curl -I -s application:5000
HTTP/1.0 500 INTERNAL SERVER ERROR

This example with an exception shows that the application can't reach server. Options used In the above command,
-I option -> shows the header information
-s option -> silences the response body.

Curl command with -O option is  used to download the file :
Usage :
curl -O http://webname.com/myfile.tar.gz #Save the file as myfile.tar.gz

227. Explain how to enable curl on Ubuntu LAMP stack?

To enable curl on Ubuntu, first, install libcurl, once done use following command /etc/init .d /apache2 restart or service apache2 restart.

228. How to get a list of currently running processes and resource utilization in Linux?

Top is the command used to get the list of running processes and resource utilization (RAM or CPU usage). It gives  all the information about each process running on the host :
Process ID (PID)
Owner of the process(USER)
Priority of process(PR)
Percentage of CPU (%CPU)
Percentage of memory
Total CPU time spends on the process.
Command used to start a process.

Most commonly used options with the top  command are below –
top -u -> Process by a user.
top – i -> exclude idle tasks
top -p -> Show a particular process

229. What is the process in a Linux context?

A process is a running program. Processes can be started from the GUI or the command line. Processes can also start other processes. Whenever a process runs, Linux keeps track of it through a process ID (PID). After booting, the first process is an initialization process called init. It is given a PID of 1. From that point on, each new process gets the next available PID.

A process can only be created by another process. We refer to the creating process as the parent and the created process as the child. The parent process spawns one or more child processes. The spawning of a process can be accomplished in one of several ways. Each requires a system call (function call) to the Linux kernel. These function calls are fork(), vfork(), clone(), wait(), and exec().

230. What are Regular Expressions(regex)? What is the meaning of *,+,? In regular expression?

A regular expression (regex) is a string that expresses a pattern used to match against other strings. The pattern will either match some portion of another string or not. There is a list of predefined metacharacters used in a regex.
1. * Used to match the preceding character if it appears 0 or more times
2. +Used to match the preceding character if it appears 1 or more times
3. ? Used to match the preceding character if it appears 0 or 1 time

231. Explain list of daemon responsible for event tracking in Linux system & signals given to the syslogd?

syslogd daemon process facilitates the event tracking in a Linux system and logs useful information or future analysis. syslogd provides two system utilities, one for logging and other for the kernel messages. syslogd mainly reacts to the set of signals given by users.

Some of the signals given to syslogd:

SIGHUP: This signal instructs syslogd to perform a re-initialization step. All open files are then closed, the configuration file (default is /etc/syslog.conf) will be reread and the syslog facility will be started again.

SIGTERM: syslogd will die.

SIGINT, SIGQUIT: If debugging is enabled these are then ignored, otherwise syslogd will die.

SIGUSR1: Switch the debugging on/off. This option can only be used if the syslogd is started with the - d debug option.

SIGCHLD: Wait for Childs if some were born, because of the waiting messages.

232. How do you make a file copied to a new user account automatically upon user account creation?

Store the file in /etc/skel directory.

233. Explain about /etc/skel directory?

The /etc/skel directory contains files and directories that are automatically copied over to a new user's home directory when such user is created by the useradd program.

/etc/skel allows a system administrator to create a default home directory for all new users on a computer or network and thus to make certain that all users begin with the same settings or environment.

Several user configuration files are placed in /etc/skel by default when the operating system is installed. Typically they might include .bash_profile, .bashrc, .bash_logout, dircolors, .inputrc and .vimrc. The dots preceding the names of these files indicate that they are hidden files, i.e., files that are not normally visible in order to avoid visual clutter and help reduce the chances of accidental damage.

234. How do you make a new user to reset his password upon his first login?

# chage -l <username>

235. Which files stores the user min UID, max UID, password expiration settings, password encryption method being used etc.,?

/etc/login.defs

236. Create users home directory in /home1 directory instead of default /home directory. This gets applicable to any new users who gets created i.e the home directory of that user should be /home1/<UserName>/ ?

Edit /etc/default/useradd
Change the line : HOME=/home1
Save the changes and exit. After this any new users home directory would be under /home1

To check the useradd defaults using the command,
# useradd -D
OR
# cat /etc/default/useradd

After this you can add users with the command “useradd <UserName>”. This would create the users home directory with the name of the user under the specified HOME directory as defined in /etc/default/useradd.

237. What are the possible causes when an user failed to login into a Linux system (physical/remote console); despite providing proper credentials?

Here are the possible reasons why an user fails to login into console:

1. Account Locked.
When user tries to login via GUI receive an error “authentication failure” after entering password and it goes back to the user list prompt.
In CLI mode, after entering user password, it would fail with an error “incorrect password”. However, if user tries “su” from root account, access would get granted.

2. Account Expired.
When account expired, an error notifying about the same would be shown up.

3. Shell Disabled
After entering password in GUI, system shows a progress, however, could come back the login prompt. When this user attempts login via CLI, would receive an error “This account is currently not available”. For example, do disable shell of an user “test” : #usermod -s /sbin/nologin test (this only locks only terminal login, however, GUI login would work)

4. Only Non-root Users Failed To Login.
If all non-root users are unable to login via GUI/CLI, however, root could login then this could be because of the file “/etc/nologin” presence on the system.

5. Only Non-root Users Failed To Login in CLI.
If all non-root users are unable to login via CLI, however, can login via GUI then it would be because of /tmp space limitations. Need to check if /tmp is configured and mounted separately and check free space under /tmp.

6. User login failed from GUI or from text console, however, could do su.
If an user fails to login from GUI/Console, however, could login from other user accounts by running ‘su’ then it could be due to pam restrictions. One could use “pam_access” module to restrict login. Need to add :
account required pam _access.so
to files : /etc/pam.d/login & /etc/pam.d/gdm-*
After this add ” – : <UserName> : ALL ” to /etc/security/access.conf file. For example to limit user “test”, we could add below line to access.conf file;
– : test : ALL
{{ there would an error “permission denied” in GUI when user is restricted to login via pam}}

7. Only root user login failed from console, however, works in GUI.
This could be because of no terminals available or defined in /etc/securetty file.
If an user failed to login remotely via ssh then the reasons could be different. Here are the reasons:

8. User Restricted.
If “AllowUsers” parameter is configured in /etc/ssh/sshd_config then need to add required user to this list to get access.

9. Max Logins Set.
If “maxlogins” parameter is set in /etc/security/limits.conf then user would be allowed up to the parameter set and further connections would be denied. There could be “maxsyslogins” configured as well to limit concurrent access to a system.

238. What does ‘ivh’ represents in rpm -ivh <PackageName> command?

i – install
v – verbose mode
h – hash mode where it would print ## characters as the installation progresses

239. What is the difference between rpm -F <PackageName> and rpm -U <PackageName>?

rpm -F = Basically freshens a package which in turn upgrades an existing package, otherwise doesn’t install it if an earlier version not found.
rpm -U = Upgrades an existing package if exists otherwise install it.

240. How to find to which package the “ls” commands belongs to (to find out package responsible for this command)?

# rpm -qf /bin/ls #this would tell about the package to which this command (binary file) belongs to if installed by that package.

241. How to check what file systems are mounted and their read/write status?

# cat /etc/mtab
# cat /proc/mounts
# mount

# df -Th #this would not tell the read/write status

242. How do you remount a file system read only on the fly?

# mount -o remount,ro <Mountpoint>
To make a file system gets mounted read only during boot, need to edit fstab.

243. Command used to convert ext2 file system into ext3.

# tune2fs -j <device or file system name>

244. How to set “rw” permissions on file for a user and disable for other users except root user (exclusive permissions)?

Use “setfacl -m u:<UserName>:<PermissionBits> <File/FolderPath>
# setfacl -m u:<UserName>:rw /testfile
To read use “getfacl” command: #getfacl /testfile

245. How to find out the shadow password encryption method being used in Linux? How could this be changed (example : from md5 to sha512)?

Check in /etc/login.defs
grep -i crypt /etc/login.defs
# Use SHA512 to encrypt password.
ENCRYPT_METHOD SHA512

Check using “authconfig” command,
# authconfig --test | grep hashing
password hashing algorithm is sha512

Check the password beginning character in the second field of /etc/shadow file:
If it begins with = $6 > indicates sha512
$5 > sha256
$1 > md5

To Change Password Encryption Method to sha512:
# authconfig –passalgo=sha512 –update 

246. How to manually add user without using “useradd/adduser” or “system-config-user” utilities?

Create required directory under /home (default home directory for all local users) and set permissions.
# mkdir /home/manualusr
# chmod 700 /home/manualusr
ls -ld /home/manualusr
drwx------. 2 root root 6 Jun 28 06:57 /home/manualusr

Edit /etc/passwd file to manually set required parameters for the new user “manualusr”:
# vipw (this command would block multiple edits of /etc/passwd file)
manualusr:x:2000:2000:local user:/home/manualusr:/bin/bash
 use the command 'vipw -s' to modify /etc/shadow 
# grep manualusr /etc/passwd
manualusr:x:1002:1002:local user:/home/manualusr:/bin/bash
 use the command 'vigr -s' to modify /etc/gshadow 

Create required group by editing /etc/group file using command ‘vigr’:
#vigr
manualusr:x:1002:

Next step is to create the local profile files for the new user by copying from /etc/skel.
# cp -arv /etc/skel/. /home/manualusr/

Change permissions of all the files under /home/manualusr to be owned by new user:
#chown -R manualusr:manualusr /home/manualusr

Try logging in as new manualusr and test.

For user mail requirement, need to create a proper file under /var/spool/mail (default mail box location) with username and permissions:
# cd /var/spool/mail
# touch manualusr
# chown manualusr:mail manualusr
# chmod 660 manualusr

247. Which command to be used to check the shell being used?

# echo $SHELL
# echo $0

2) How to check if the syslog service is running?
 
# /etc/init.d/rsyslog status OR service rsyslog status 

# systemctl status rsyslog.service (in RHEL7.x).

248. By default log files are set to get rotated on weekly basis, how to make this gets rotated on monthly basis?

Edit /etc/logrotate.conf and change below lines
# rotate log files monthly
monthly

Save changes and if you want to rotate the log files immediately then run the command:
# logrotate -f /etc/logrotate.conf

249. What does /var/log/wtmp and /var/log/btmp files indicates and what do they store?

These files are used to store user login/logout details since from the date of creation.
The user login, logout, terminal type etc are stored in /var/log/wtmp and this is not a user-readable file, so “last” command reads data from this file (or the file designated by the -f flag).

All un-successful(bad) login attempts are recorded in /var/log/btmp which could be displayed using the command “lastb”. All these login/logout events would also get recorded in /var/log/secure file (this file usually stores all authentication/authorization events).

Like-wise, there is /var/log/lastlog which records most previous successful login event of users. In earlier RHEL versions (RHEL 5.x) there used to be a file /var/log/faillog to hold failed login events which had become obsolete since RHEL6.1 and is no longer available.

250. How to find out the configuration files installed by a package (take into consideration of the “coreutils” package)?

# rpm -qc coreutils

To list out only the document files installed by coreutils package:-
# rpm -qd coreutils

To list out all the files installed by this package:-
# rpm -ql coreutils
# rpm -q --filesbypkg coreutils

To list out dependencies :-
# rpm -qR coreutils

To list out packages which require this package:-
# rpm -q --whatrequires coreutils

To find out more information of this package:-
#rpm -qi coreutils

To find out any scripts executed by this package:-
#rpm -q -scripts coreutils

                                                                                           MENU         PREVIOUS | NEXT

No comments:

Post a comment