Archives

Increase password prompt timeout for sshd

Do you want to control the login timeout for the SSH server? You can control it with the LoginGraceTime setting.

LoginGraceTime
The server disconnects after this time if the user has not successfully logged in. If the value is 0, there is no time limit. The default is 120 seconds.

sshd_config man page

Use your favorite text editor to edit the SSH server settings:

nano /etc/ssh/sshd_config

Look for the LoginGraceTime value – add it or adjust its value:

LoginGraceTime 10

We adjusted it here to 10 seconds. Users will have 10 seconds to log in to the SSH server. Don’t forget to restart the SSH server:

service sshd restart

Resources:
sshd_config man page

CentOS – switch from GUI to terminal

You installed CentOS with the GUI and you want to remove it later? Instead of removing it, you can just switch the system from GUI to the terminal. For this, we will use systemd targets.

Below are the systemd targets used in RedHat/CentOS 7+:

RunlevelTarget Units Description
0runlevel0.target, poweroff.target Shut down and power off the system.
1runlevel1.target, rescue.targetSet up a rescue shell.
2runlevel2.target, multi-user.targetSet up a non-graphical multi-user system.
3runlevel3.target, multi-user.targetSet up a non-graphical multi-user system.
4runlevel4.target, multi-user.targetSet up a non-graphical multi-user system.
5runlevel5.target, graphical.targetSet up a graphical multi-user system.
6runlevel6.target, reboot.targetShut down and reboot the system.

To switch from GUI to terminal/non-graphical user interface, use:

systemctl set-default multi-user.target
reboot
CentOS GUI

To switch from terminal/non-graphical user interface to GUI, use:

systemctl set-default graphical.target
reboot
CentOS Non-GUI

Resources:
SYSTEMD TARGETS

Modify password prompt timeout in CentOS

The default login password prompt interval is 60 seconds in CentOS.

CentOS login screen

You can adjust this value by modifying the LOGIN_TIMEOUT value in the file /etc/login.defs.

LOGIN_TIMEOUT (number)
Max time in seconds for login.

login.defs man page

Just edit the file /etc/login.defs with your preferred text editor and add/adjust the value:

LOGIN_TIMEOUT 5

In this case, we’ve set the max login tine to 5 seconds. Use the value that suits your needs. Save the file and reboot the server. The new value is used.

Resources:
login.defs man page

Export a MySQL/MariaDB database

Exporting a database can be done very easily from phpMyAdmin/ from your web hosting control panel (cPanel, DirectAdmin, VestaCP etc). But you can also export databases from the command line with the mysqldump utility.

With mysqldump you can export a single database, all databases or a list of databases:

shell> mysqldump [options] db_name [tbl_name …]
shell> mysqldump [options] –databases db_name …
shell> mysqldump [options] –all-databases

mysqldump help page

To backup one database, use the command below. It will save the database as an SQL file.

mysqldump -u db_user -p db_name > db_name.sql

If you are running the commands as root, you don’t need the -u, -p parameters.

root@web [~]# mysqldump admin_wp74 > admin_wp74.sql
root@web [~]# 

If you want to archive the exported database to save space, use:

mysqldump -u db_user -p db_name | gzip > /home/db_name.sql.gz

root@web [~]# mysqldump admin_wp74 | gzip > /root/admin_wp74.sql.gz
root@web [~]#

Resources:
mysqldump help

How to install VIM enhanced

Vi is a text editor that comes preinstalled on CentOS distributions. Anyway, the Vi version that is installed is vim-minimal. You can check which version you have with the vi –version command:

root@www [/]# vi --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug  9 2019 03:16:06)
Included patches: 1-207, 209-629
Modified by <bugzilla@redhat.com>
Compiled by <bugzilla@redhat.com>
Small version without GUI.  Features included (+) or not (-):
............

You can see the text “small version without GUI”. The command will also list all the available options of the software. If you want more features available you need the Vim enhanced version, vim-enhanced.

We check first which version is available in the yum repository:

root@www [/]# yum info vim-enhanced
Loaded plugins: fastestmirror, tsflags, universal-hooks
Loading mirror speeds from cached hostfile
 * EA4: 208.74.123.61
 * cpanel-addons-production-feed: 208.74.123.61
 * cpanel-plugins: 208.74.123.61
 * base: mirror.us.oneandone.net
 * epel: mirror.compevo.com
 * extras: mirror.us.oneandone.net
 * updates: mirror.us.oneandone.net
Installed Packages
Name        : vim-enhanced
Arch        : x86_64
Epoch       : 2
Version     : 7.4.629
Release     : 6.el7
Size        : 2.2 M
Repo        : installed
From repo   : base
Summary     : A version of the VIM editor which includes recent enhancements
URL         : http://www.vim.org/
License     : Vim
Description : VIM (VIsual editor iMproved) is an updated and improved version of the
            : vi editor.  Vi was the first real screen-based editor for UNIX, and is
            : still very popular.  VIM improves on vi by adding new features:
            : multiple windows, multi-level undo, block highlighting and more.  The
            : vim-enhanced package contains a version of VIM with extra, recently
            : introduced features like Python and Perl interpreters.
            :
            : Install the vim-enhanced package if you'd like to use a version of the
            : VIM editor which includes recently added enhancements like
            : interpreters for the Python and Perl scripting languages.  You'll also
            : need to install the vim-common package.

So, to install VIM use:

yum install –y vim-enhanced

root@www [/]# yum install –y vim-enhanced
Loaded plugins: fastestmirror, tsflags, universal-hooks
Loading mirror speeds from cached hostfile
 * EA4: 208.74.123.61
 * cpanel-addons-production-feed: 208.74.123.61
 * cpanel-plugins: 208.74.123.61
 * base: centos.host-engine.com
 * epel: fedora-epel.mirror.lstn.net
 * extras: ftpmirror.your.org
 * updates: centos.mirrors.hoobly.com
Resolving Dependencies
--> Running transaction check
---> Package vim-enhanced.x86_64 2:7.4.629-6.el7 will be installed
--> Processing Dependency: vim-common = 2:7.4.629-6.el7 for package: 2:vim-enhanced-7.4.629-6.el7.x86_64
--> Running transaction check
---> Package vim-common.x86_64 2:7.4.629-6.el7 will be installed
--> Processing Dependency: vim-filesystem for package: 2:vim-common-7.4.629-6.el7.x86_64
--> Running transaction check
---> Package vim-filesystem.x86_64 2:7.4.629-6.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                     Arch                                Version                                        Repository                         Size
========================================================================================================================================================================
Installing:
 vim-enhanced                                x86_64                              2:7.4.629-6.el7                                base                              1.1 M
Installing for dependencies:
 vim-common                                  x86_64                              2:7.4.629-6.el7                                base                              5.9 M
 vim-filesystem                              x86_64                              2:7.4.629-6.el7                                base                               11 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 7.0 M
Installed size: 23 M
Is this ok [y/d/N]: y
Downloading packages:
(1/3): vim-enhanced-7.4.629-6.el7.x86_64.rpm                                                                                                     | 1.1 MB  00:00:00
(2/3): vim-filesystem-7.4.629-6.el7.x86_64.rpm                                                                                                   |  11 kB  00:00:00
(3/3): vim-common-7.4.629-6.el7.x86_64.rpm                                                                                                       | 5.9 MB  00:00:01
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   6.8 MB/s | 7.0 MB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:vim-filesystem-7.4.629-6.el7.x86_64                                                                                                                1/3
  Installing : 2:vim-common-7.4.629-6.el7.x86_64                                                                                                                    2/3
  Installing : 2:vim-enhanced-7.4.629-6.el7.x86_64                                                                                                                  3/3
  Verifying  : 2:vim-enhanced-7.4.629-6.el7.x86_64                                                                                                                  1/3
  Verifying  : 2:vim-common-7.4.629-6.el7.x86_64                                                                                                                    2/3
  Verifying  : 2:vim-filesystem-7.4.629-6.el7.x86_64                                                                                                                3/3

Installed:
  vim-enhanced.x86_64 2:7.4.629-6.el7

Dependency Installed:
  vim-common.x86_64 2:7.4.629-6.el7                                                vim-filesystem.x86_64 2:7.4.629-6.el7

Complete!
root@www [/]#

As you can see, the command will also install the required packages vim-filesystem and vim-common.

Notice that the basic editor will remain. You will access the basic Vi with the command vi and the enhanced Vi with the vim command.

Resources:
Vim – the ubiquitous text editor

Page 4 of 10
1 2 3 4 5 6 10