Wednesday, September 14, 2016

How to display welcome message if user has logged in from a particular IP (or host)?

1. Edit /etc/ssh/sshd_config and change "PrintLastLog" to "no". Save file and restart sshd

2. If you want to display this message for a specific user edit (or create) ~user/.bash_profile and add these lines at the end of the file:

==========cut here==========
REMOTE_IP=`echo $SSH_CONNECTION | cut -f1 -d " "`
if [ $REMOTE_IP == '10.5.226.172' ] ;
then echo "So, it's you again..." ;
else echo "Hi, stranger...";
fi
==========cut here==========

3. If you want this for all users, the same snippet goes to /etc/profile of in a new file in /etc/profile.d

Sunday, September 11, 2016

How to update a single package in ubuntu/kubuntu

In order to update a single package using the CLI: you need to add the option '--only-upgrade install'

sudo apt-get --only-upgrade install <packagename>

e.g., sudo apt-get --only-upgrade install ack

Reading package lists... Done
Building dependency tree      
Reading state information... Done
Skipping **ack**, it is not installed and only upgrades are requested.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Upgrade firefox in Ubuntu/Kubuntu

Step1: Adding Firefox PPA key

Copy paste this code in your terminal
   
sudo add-apt-repository ppa:mozillateam/firefox-next

Step 2: Update

→ To finish indexing the repository

→ Please don’t close the terminal window before completing the update process.
   
sudo apt-get update

Step 3: Installing/updating Firefox

sudo apt-get install firefox

Friday, September 9, 2016

apt-get basic options

apt-get - Package management (like yum) via apt-get runs hand-in-hand with the /etc/apt/sources.list file.

dpkg - is a tool to install, build, remove and manage Debian packages(like rpm).

List packages - apt-cache pkgnames
Search for a package - apt-cache search vsftpd
Find all packages starting with ‘vsftpd‘-   -apt-cache pkgnames vsftpd
Check Package Information - apt-cache show netcat


Update System Packages -  sudo apt-get update
he ‘update‘ command is used to resynchronize the package index files from the their sources specified in /etc/apt/sources.list file. The update command fetched the packages from their locations and update the packages to newer version.


Upgrade Software Packages - sudo apt-get upgrade

The ‘upgrade‘ command is used to upgrade all the currently installed software packages on the system. Under any circumstances currently installed packages are not removed or packages which are not already installed neither retrieved and installed to satisfy upgrade dependencies.

More: http://www.tecmint.com/useful-basic-commands-of-apt-get-and-apt-cache-for-package-management/

How to check the processor is 32 or 64 bit

Method - 1

You can use lscpu


someuser@somelaptop:~$ lscpu
Architecture:          i686           # <-- your kernel is 32 bit
CPU op-mode(s):        32-bit, 64-bit # <-- your cpu can handle 32 or 64 bit instructions
CPU(s):                4
Thread(s) per core:    2
Core(s) per socket:    2
CPU socket(s):         1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 37
Stepping:              5
CPU MHz:               1199.000
Virtualisation:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              3072K 

Further explanation of the Architecture field:
X86, i686, or i386 means you are running a 32 bit kernel. 
X86_64 , amd64 , or X64 means you are running a 64 bit kernel. 

Method -2

uname -p give the architecture of the processor.


X86, i686, or i386 means you are running a 32 bit kernel. 
X86_64 , amd64 , or X64 means you are running a 64 bit kernel. 

Method -3 

With lshw
Long answer: run sudo lshw
Slightly shorter answer: sudo lshw -c cpu
Output:

 *-cpu                   
       description: CPU
       product: AMD Turion(tm) X2 Dual-Core Mobile RM-75
       vendor: Advanced Micro Devices [AMD]
       physical id: 4
       bus info: cpu@0
       version: Turion X2 Mobile RM-75
       slot: Socket M2/S1G1
       size: 550MHz
       capacity: 4GHz
       width: 64 bits
       clock: 200MHz
       capabilities: fpu fpu_exception wp vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp x86-64 3dnowext 3dnow constant_tsc rep_good nopl nonstop_tsc extd_apicid pni cx16 lahf_lm cmp_legacy svm extapic cr8_legacy 3dnowprefetch osvw skinit hw_pstate lbrv svm_lock nrip_save vmmcall cpufr

Even shorter answer: sudo lshw -c cpu | grep width
Output: width: 64 bits



 

Wednesday, September 7, 2016

Change Apache MPM from Prefork to Worker


  • By default Apache will use prefork MPM.
  • you can verify it by executing httpd -l . 
[user@linuxbox ~]$ httpd -l
   Compiled in modules:
    core.c
    prefork.c
    http_core.c
    mod_so.c

  • If you want to change it into worker MPM. Open the file 
     vi /etc/sysconfig/httpd

and uncomment the line 
      #HTTPD=/usr/sbin/httpd.worker

Then if you check again the command httpd -l you can still see prefork.c listed there. But that doesn't mean that Apache now using Prefork. It just mean that at the time when apache configured it was compiled with the option prefork. 

So how do you know which MPM apache is using?

Just check the Apache process using ps aux | grep httpd  or use top command

  • httpd means Apache is running as prefork
  • httpd.worker means it is running as worker



Wednesday, June 8, 2016

How to show/list the users in a MySQL database

To show/list the users in a MySQL database, first log into your MySQL server as an administrative user using the mysql client, then run this MySQL query:
mysql> select * from mysql.user;
However, note that this query shows a large listing of MySQL user information, including user permission information, so as a practical matter you may want to trim down some of the fields to display, something like this:
mysql> select host, user, password from mysql.user;
The next section provides details and background information about this second query.

How to reduce the amount of ‘user’ information shown

You can get a listing of the fields in the mysql.user table by running this MySQL query:
mysql> desc mysql.user;
On my current server this shows the following 37 columns of MySQL user information, as shown here:
mysql> desc mysql.user;
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Field                 | Type                              | Null | Key | Default | Extra |
+-----------------------+-----------------------------------+------+-----+---------+-------+
| Host                  | char(60)                          | NO   | PRI |         |       | 
| User                  | char(16)                          | NO   | PRI |         |       | 
| Password              | char(41)                          | NO   |     |         |       | 
| Select_priv           | enum('N','Y')                     | NO   |     | N       |       | 
| Insert_priv           | enum('N','Y')                     | NO   |     | N       |       | 
| Update_priv           | enum('N','Y')                     | NO   |     | N       |       | 
| Delete_priv           | enum('N','Y')                     | NO   |     | N       |       | 
| Create_priv           | enum('N','Y')                     | NO   |     | N       |       | 
| Drop_priv             | enum('N','Y')                     | NO   |     | N       |       | 
| Reload_priv           | enum('N','Y')                     | NO   |     | N       |       | 
| Shutdown_priv         | enum('N','Y')                     | NO   |     | N       |       | 
| Process_priv          | enum('N','Y')                     | NO   |     | N       |       | 
| File_priv             | enum('N','Y')                     | NO   |     | N       |       | 
| Grant_priv            | enum('N','Y')                     | NO   |     | N       |       | 
| References_priv       | enum('N','Y')                     | NO   |     | N       |       | 
| Index_priv            | enum('N','Y')                     | NO   |     | N       |       | 
| Alter_priv            | enum('N','Y')                     | NO   |     | N       |       | 
| Show_db_priv          | enum('N','Y')                     | NO   |     | N       |       | 
| Super_priv            | enum('N','Y')                     | NO   |     | N       |       | 
| Create_tmp_table_priv | enum('N','Y')                     | NO   |     | N       |       | 
| Lock_tables_priv      | enum('N','Y')                     | NO   |     | N       |       | 
| Execute_priv          | enum('N','Y')                     | NO   |     | N       |       | 
| Repl_slave_priv       | enum('N','Y')                     | NO   |     | N       |       | 
| Repl_client_priv      | enum('N','Y')                     | NO   |     | N       |       | 
| Create_view_priv      | enum('N','Y')                     | NO   |     | N       |       | 
| Show_view_priv        | enum('N','Y')                     | NO   |     | N       |       | 
| Create_routine_priv   | enum('N','Y')                     | NO   |     | N       |       | 
| Alter_routine_priv    | enum('N','Y')                     | NO   |     | N       |       | 
| Create_user_priv      | enum('N','Y')                     | NO   |     | N       |       | 
| ssl_type              | enum('','ANY','X509','SPECIFIED') | NO   |     |         |       | 
| ssl_cipher            | blob                              | NO   |     | NULL    |       | 
| x509_issuer           | blob                              | NO   |     | NULL    |       | 
| x509_subject          | blob                              | NO   |     | NULL    |       | 
| max_questions         | int(11) unsigned                  | NO   |     | 0       |       | 
| max_updates           | int(11) unsigned                  | NO   |     | 0       |       | 
| max_connections       | int(11) unsigned                  | NO   |     | 0       |       | 
| max_user_connections  | int(11) unsigned                  | NO   |     | 0       |       | 
+-----------------------+-----------------------------------+------+-----+---------+-------+
37 rows in set (0.10 sec)
So for most cases where you want to show MySQL user accounts you'll probably want to limit your MySQL users' query to a few important columns, something like this:
select host, user, password from mysql.user;

How can I show user's privileges

SHOW GRANTS [FOR user]
This statement lists the GRANT statement or statements that must be issued to duplicate the privileges that are granted to a MySQL user account. The account is named using the same format as for the GRANT statement; for example, 'jeffrey'@'localhost'. If you specify only the user name part of the account name, a host name part of '%' is used. For additional information about specifying account names, see Section 12.5.1.3, “GRANT Syntax”.
mysql> SHOW GRANTS FOR 'root'@'localhost';
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
To list the privileges granted to the account that you are using to connect to the server, you can use any of the following statements:
SHOW GRANTS;
SHOW GRANTS FOR CURRENT_USER;
SHOW GRANTS FOR CURRENT_USER();
As of MySQL 5.0.24, if SHOW GRANTS FOR CURRENT_USER (or any of the equivalent syntaxes) is used in DEFINER context, such as within a stored procedure that is defined with SQL SECURITY DEFINER), the grants displayed are those of the definer and not the invoker.
SHOW GRANTS displays only the privileges granted explicitly to the named account. Other privileges might be available to the account, but they are not displayed. For example, if an anonymous account exists, the named account might be able to use its privileges, but SHOW GRANTS will not display them.
SHOW GRANTS requires the SELECT privilege for the mysql database.