How to install Node.js on Ubuntu/CentOS

    If you want to easy install Node.js on Ubuntu or RHEL – based systems such as CentOS, I’m just gonna point you towards Nodesource. It’s the easiest thing to do since sliced bread.

    However, if you’re into more heavy development and you would like an RVM-like setup, you can try NVM. You will be able to run multiple Node.js versions side by side and more granular control.

    Enjoy!

    Ubuntu 16.04 – Downgrade php from 7.0 to 5.6

    So I got a new Ubuntu box and they are loading PHP 7.0 by default, which kinda breaks some apps right now. Lucky for us, I got an answer from a handy guy on AskUbuntu:

    Remove the installed PHP packages (if you installed them):

    sudo apt purge dpkg -l | grep php| awk '{print $2}' |tr "\n" " "

    Add the PPA
    sudo add-apt-repository ppa:ondrej/php

    Install your PHP Version
    sudo apt-get update
    sudo apt-get install php5.6

    Enjoy!

    AttributeError: ‘module’ object has no attribute ‘DeprecatedIn12’

    If you are playing with certbot on CenOS7 and you encounter the thing below, it’s due to a Python library that should be upgraded:

    AttributeError: ‘module’ object has no attribute ‘DeprecatedIn12’

    pip install cryptography –upgrade

    pip install –upgrade pip

    then again:

    pip install cryptography –upgrade

    After this, you should be able to use certbot without any issues.

    Format / mount ec2 volume

    So you added a new volume to a server and you want to mount it quick.

    • Use lsblk to spot the new added volume:

    [root@devserver ~]# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    xvda 202:0 0 8G 0 disk
    ??xvda1 202:1 0 8G 0 part /
    xvdb 202:16 0 8G 0 disk /var/www/html
    xvdf 202:80 0 16G 0 disk /var/lib/mysql
    xvdg 202:96 0 16G 0 disk /home
    xvdh 202:112 0 32G 0 disk

    • Use mkfs to create a filesystem on the partition:

    [root@devserver ~]# mkfs -t ext4 /dev/xvdf
    mke2fs 1.42.9 (28-Dec-2013)
    /dev/xvdf is mounted; will not make a filesystem here!
    [root@devserver ~]# mkfs -t ext4 /dev/xvdh
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    2097152 inodes, 8388608 blocks
    419430 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2155872256
    256 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
    4096000, 7962624

    Allocating group tables: done
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done

    • Create a folder and mount the newly created partition:

    [root@devserver ~]# mkdir /misc
    [root@devserver ~]# mount /dev/xvdh /misc
    [root@devserver ~]# df -h |grep misc
    Filesystem Size Used Avail Use% Mounted on
    /dev/xvdh 32G 49M 30G 1% /misc

    • Edit /etc/fstab so the partition is mounted at reboot:

    /dev/xvdh /misc ext4 defaults,nofail 0 2

    Done!

    Amazon EC2 change hostname – OpenSUSE

    I am just getting to know OpenSUSE and it’s been driving me insane with the hostname not being persistent even if you change it via “hostnamectl” or entering the new hostname in “/etc/hostname”.

    In EC2, you have to open up yast and uncheck the “change hostname via DHCP tick box” in the network card settings.

    Self signed SSL – quick and dirty

    If you’re in the market for quickly getting a self signed SSL certificate done:

    openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
    openssl rsa -passin pass:x -in server.pass.key -out server.key
    openssl req -new -key server.key -out server.csr
    openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

    ls -la

    -rw-r–r–. 1 root root 1387 Apr 27 08:49 server.crt
    -rw-r–r–. 1 root root 1098 Apr 27 08:49 server.csr
    -rw-r–r–. 1 root root 1679 Apr 27 08:48 server.key

    Enjoy

    Changing SSH port in CentOS with SELinux enabled

    So, you wanted to change the ssh port, but when you restart sshd : “systemctl restart sshd” – it doesn’t wanna come up due to selinux not allowing it:

    Apr 26 12:31:21 ip-10-0-0-169 systemd[1]: Starting OpenSSH server daemon…
    — Subject: Unit sshd.service has begun start-up
    — Defined-By: systemd
    — Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel

    — Unit sshd.service has begun starting up.
    Apr 26 12:31:21 ip-10-0-0-169 polkitd[13985]: Unregistered Authentication Agent for unix-process:14017:9027294 (system bus name :1.65, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bu
    Apr 26 12:31:21 ip-10-0-0-169 sshd[14022]: error: Bind to port 25252 on 0.0.0.0 failed: Permission denied.
    Apr 26 12:31:21 ip-10-0-0-169 sshd[14022]: error: Bind to port 25252 on :: failed: Permission denied.
    Apr 26 12:31:21 ip-10-0-0-169 sshd[14022]: fatal: Cannot bind any address.
    Apr 26 12:31:21 ip-10-0-0-169 systemd[1]: sshd.service: main process exited, code=exited, status=255/n/a
    Apr 26 12:31:21 ip-10-0-0-169 systemd[1]: Unit sshd.service entered failed state.
    Apr 26 12:31:21 ip-10-0-0-169 systemd[1]: sshd.service failed.

    Enter semanage:

    [root@ip-10-0-0-169 log]# semanage port -l | grep ssh
    ssh_port_t tcp 22
    [root@ip-10-0-0-169 log]# semanage port -a -t ssh_port_t -p tcp 25252

    (this command will take a while to complete, so just let it be)

    restart sshd: systemctl restart sshd 

    voila! it’s alive!

    — Unit sshd.service has begun starting up.

    Fix ESC git diff / FreeBSD

    So let’s say you are trying to do a git diff and it looks like crap:

    ESC[1mdiff –git a/node_modules/namecheap/namecheap.js b/node_modules/namecheap/namecheap.jsESC[m
    ESC[1mindex df87fc0..dde8ea0 100644ESC[m
    ESC[1m— a/node_modules/namecheap/namecheap.jsESC[m
    ESC[1m+++ b/node_modules/namecheap/namecheap.jsESC[m
    ESC[36m@@ -276,15 +276,15 @@ESC[m ESC[mnamecheap.prototype = {ESC[m

    fix it by doing :

    git config –global core.pager “less -r”

    Enjoy

    [SOLVED] vmware-hostd high cpu usage

    This can get quite annoying at times, but it if you notice vmware-hostd taking up cpu, you can disable VMs sharing by going to Edit > Preferences > Shared VMs > Disable Sharing.

    Will fix instantly.

    Enjoy!

    git – large file removed but still can’t push

    So i have a git repo where a large file got commited by mistake:

    git push origin master
    Counting objects: 2480, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (1922/1922), done.
    Writing objects: 100% (2480/2480), 484.14 MiB | 15.10 MiB/s, done.
    Total 2480 (delta 697), reused 0 (delta 0)
    remote: error: GH001: Large files detected. You may want to try Git Large File Storage – https://git-lfs.github.com.
    remote: error: Trace: b3405c85f13ee38933ee3ba62be554e1
    remote: error: See http://git.io/iEPt8g for more information.
    remote: error: File auf2/aaaaa.mp4 is 389.00 MB; this exceeds GitHub’s file size limit of 100.00 MB

    I removed the file, commited bla bla and still in the commit history, the file would exist and i would get the same message over and over again.

    In order to fix this, i had to remove it from the history using the command below:

    git filter-branch –index-filter ‘git rm -r –cached –ignore-unmatch auf2/aaaaa.mp4’ HEAD

    Enjoy!