[HOW TO] set application log to rsyslog on Ubuntu server

Depending on your application, also your purpose, you want to direct the log to fixed log path. So, if you are using rsyslog as a syslog service on Ubuntu, please follow this article.

I am using trigger to do this.

Go to log path
root@sta-tn:/etc/rsyslog.d#

then write a sub-rsyslog configuration.
root@sta-tn:/etc/rsyslog.d# vim 10-sta.conf 
if $programname == 'STA'  then {  
/var/log/sta.log    
stop 
}

You can declare more directive here. Then restart rsyslog service
root@sta-tn:/etc/rsyslog.d# systemctl restart rsyslog

Another way, you can use imfile module to do this.

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 

[HOW TO] The following signatures couldn't be verified because the public key is not available: NO_PUBKEY

sky@zabbix4-srv-01:/opt/packages$ sudo apt-get updateGet:1 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial InRelease [7096 B]Hit:2 http://security.ubuntu.com/ubuntu xenial-security InReleaseGet:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease [23.9 kB]Hit:4 http://us.archive.ubuntu.com/ubuntu xenial InReleaseGet:5 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial/main Sources [1196 B]Ign:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InReleaseHit:6 http://us.archive.ubuntu.com/ubuntu xenial-updates InReleaseGet:7 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial/main amd64 Packages [2697 B]Get:8 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial/main i386 Packages [2685 B]Hit:9 http://us.archive.ubuntu.com/ubuntu xenial-backports InReleaseFetched 37.5 kB in 1s (33.2 kB/s)Reading package lists... DoneW: GPG error: http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4F4EA0AAE5267A6CW: The repository 'http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease' is not signed.N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.N: See apt-secure(8) manpage for repository creation and user configuration details.

sky@zabbix4-srv-01:/opt/packages$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6CExecuting: /tmp/tmp.8btYCLAEE0/gpg.1.sh --keyserverkeyserver.ubuntu.com--recv-keys4F4EA0AAE5267A6Cgpg: requesting key E5267A6C from hkp server keyserver.ubuntu.comgpg: key E5267A6C: public key "Launchpad PPA for Ond\xc5\x99ej Sur�" importedgpg: Total number processed: 1gpg:               imported: 1  (RSA: 1)


sky@zabbix4-srv-01:/opt/packages$skylab@zabbix4-srv-01:/opt/packages$ sudo apt-get updateHit:1 http://repo.zabbix.com/zabbix/4.0/ubuntu xenial InReleaseHit:2 http://security.ubuntu.com/ubuntu xenial-security InReleaseGet:3 http://ppa.launchpad.net/ondrej/php/ubuntu xenial InRelease [23.9 kB]Hit:4 http://us.archive.ubuntu.com/ubuntu xenial InReleaseHit:5 http://us.archive.ubuntu.com/ubuntu xenial-updates InReleaseHit:6 http://us.archive.ubuntu.com/ubuntu xenial-backports InReleaseFetched 23.9 kB in 1s (22.1 kB/s)Reading package lists... Done

Tiến Phan - R0039

Knowledge is Endless
Sharing for Success 

[HOW TO] using loopback files

Morning, 

Sometimes, you want to have a specified mount point for backing up. But, you could not find any free mount point. 

Also I explain why do we need to have a specified mount point.
1. To mark as a backup mount point other purpose, then nobody have a mistake with this. 
2. Clearly mount point for managing 

So, why did I us "loopback file? 
Using "loopback file", I do it. Loopback filesystems are very interesting components of Linux-like systems. Daily, we create filesystems on device (disk drive partitions). These storage devices are available as device files such as /dev/device_name. Then we mount it at a directory called a mount point. On the other hand, loopback filesystems are those that we create in files rather than a physical device. We can then mount those files as filesystems at a mount point. It is logical disk inside a file on your physical disk.

How I do it? 
Create raw file with "dd" command
$ dd if=/dev/zero of=loopbackfile.img bs=1GB count=1

then I have a 1GB file loopbackfile.img. Then I format this file to ext4 using mkfs command as follows:
$ mkfs.ext4 loopbackfile.img

and create a new directory 
$mkdir /mnt/loopback

mount the loopback file to /mnt/loopback as follows
$ mount -o loop loopbackfile.img /mnt/loopback

option "-o loop" is used to mount loopback filesystems. Also it attaches to a device called /dev/loop1 or loop2.

then I use "df -h" command
/dev/loop0      976M  2,6M  907M   1% /mnt/loopback

finally, I should add "mount -o loop loopbackfile.img /mnt/loopback" to /etc/fstab. Why? because it will follow the system startup and already have the mount point. I could not remember to add it every system boot. Of course, I need to use it as a static partition on this case. If you don't need it, you can ignore this. 

Good luck! 

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] Puppet Validation of Exec[generating file] failed: '....' is not qualified and no path was specified. Please qualify the command or specify a path

I just run executable resource in Puppet and could not run successful. Here is content of Puppet file.
root@puppet:/etc/puppet/manifests# cat exec.pp
exec { 'generating file':
cwd => '/tmp/',
command => 'for i in {1.2}.txt; do touch $name; done',
creates => '/tmp/1.txt',
}
root@puppet:/etc/puppet/manifests# puppet apply --noop exec.pp
Notice: Compiled catalog for puppet in environment production in 0.10 seconds
Error: Validation of Exec[generating file] failed: 'for name in {1.2}.txt; do touch $name; done' is not qualified and no path was specified. Please qualify the command or specify a path. at /etc/puppet/manifests/exec.pp:5

Following the notification, I should declare the qualified path of command, then I put a default path as /bin
root@puppet:/etc/puppet/manifests# vim exec.pp
exec { 'generating file':
cwd => '/tmp/',
path => '/bin',
command => 'for name in {1.2}.txt; do touch $name; done',
creates => '/tmp/1.txt',
}
root@puppet:/etc/puppet/manifests# puppet apply --noop exec.pp
Notice: Compiled catalog for puppet in environment production in 0.10 seconds
Notice: /Stage[main]/Main/Exec[generating file]/returns: current_value notrun, should be 0 (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Finished catalog run in 0.04 seconds

It works!!!

So you can do like me to fix it.

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success

[HOW TO] create a shadow hash of password

Sometimes, you may need to create a critical script to change the password of root or another user. Of course, you don't use the clear text of password. It is very risk and can leak. Then, what should we do on this case?

I want to bring you focus /ect/shadow. For sure, it is salted hash file where stores all of user's password. And it already hashed. 

It looks like this


catrulez:$6$3lOhJgJD$lUKZ0Q9LHT6YO3u1pS/0hM9yJOYTkqOh/XaR2O5xYwaPKI6TWIOEjYQSsa2XWJI7Ty.i2XQmHVdqNZDnGYiUT.:17482:0:99999:7:::

and 
$6$3lOhJgJD$lUKZ0Q9LHT6YO3u1pS/0hM9yJOYTkqOh/XaR2O5xYwaPKI6TWIOEjYQSsa2XWJI7Ty.i2XQmHVdqNZDnGYiUT

is the shadow hash corresponding to its password. 

So, in my imagination, I will create a shadow hash of password what I want to set for individual user and put it to critical script. Then it should be fine. 

Two steps:
1. Create a shadow hash 
root@catrulez:~# openssl passwd -1 -salt dsadsadd Zxcvbnm1$1$dsadsadd$y4h9pSp/9rS2kVv7x4xRB.

2. Create a user with shadow hash of password. 
root@catrulez:~# useradd -p '$1$dsadsadd$y4h9pSp/9rS2kVv7x4xRB.'  user_name

Also you can take them to script. Please clear bash history. 

Tiến Phan - R0039

Knowledge is Endless

Sharing for Success