Saturday, January 20, 2018

Fix "Found a swap file by the name"

1. If you get the following:

E325: ATTENTION
Found a swap file by the name ".file.conf.swp"
          owned by: root   dated: Wed Jan  3 11:43:03 2018
         file name: /etc/httpd/conf.d/file.conf
          modified: YES
         user name: root   host name: system-rh
        process ID: 19891
While opening file "file.conf"
             dated: Tue Jan 16 15:51:50 2018
      NEWER than swap file!

(1) Another program may be editing the same file.  If this is the case,
    be careful not to end up with two different instances of the same
    file when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.
    If this is the case, use ":recover" or "vim -r file.conf"
    to recover the changes (see ":help recovery").
    If you did this already, delete the swap file ".file.conf.swp"
    to avoid this message.


2. List all hidden files

ls -al

3. Remove troubled swap file:
rm -rf .file.conf.swp

Sunday, January 14, 2018

cURL getting "Illegal instruction" on CentOS

0. Behavior is the following:
When launching command:


curl -v -k -s -IXGET "https://www.google.com"

You get something like:

* About to connect() to www.google.com port 443 (#0)
*   Trying ... connected
* Connected to www.google.com port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* warning: ignoring value of ssl.verifyhost
* skipping SSL peer certificate verification
Illegal instruction (core dumped)



To fix the above, follow the below steps:

1. Disable AES_GCM encryption in NSS using:
 

export NSS_DISABLE_HW_GCM=1

2. Test again and shall work fine with step 0 above command.

Note: You can reset NSS_DISABLE_HW_GCM back by launching:
 

unset NSS_DISABLE_HW_GCM

Friday, January 12, 2018

Extract files from RPM file

1. View files from rpm package file:

rpm -qlp ./path/to/test.rpm

2. Extract files from valid rpm package file:

rpm2cpio ./packagecloud-test-1.1-1.x86_64.rpm | cpio -idmv

Friday, January 5, 2018

Jump to specific line number in vi

1. Display line numbers:

:set nu

2. Jump to specific line number:

:number

e.g.

:20

The above jumps to line 20

Thursday, January 4, 2018

Kill and terminate user ssh session on Linux

1. See who is connected:

who

2. Identify user session PID:

netstat -tanp

3. Kill that user session:

kill -9 PID

4. Check by running again step 1.

Wednesday, January 3, 2018

Fix Selinux context issue when attempting to start Apache httpd

1. Getting the following error when attempting to start Apache httpd:
 

httpd: Syntax error on line 88 of /etc/httpd/conf.d/file.conf permission denied

 2. Checking file.conf context you get the following:
 

 ls -lZ
-rw-r--r--. root root unconfined_u:object_r:user_home_t:s0 file.conf


 3. Fix the context using the following commnads:

semanage fcontext -a -t httpd_config_t file.conf
restorecon -v file.conf

4. Context is fine now and httpd starts properly: 

-rw-r--r--. root root unconfined_u:object_r:httpd_config_t:s0 file.conf