Setup read and write samba share in vagrant centos

Tested on vagrant centos 6.9
In your vagrant machine:

$ sudo yum install samba samba-common samba-client

Setup samba config, place this config at the bottom of the file:

$ sudo vim /etc/samba/smb.conf
...
...
[foobar]
browseable = yes
path = /srv/foobar
guest ok = yes
public = yes
read only = no
create mask = 0644
directory mask = 0755
force user = foobar
valid users = foobar
writable = yes
$ sudo /etc/init.d/smb restart

Setup your samba user password, this password will be used for mount the directory from your local machine:

$ sudo smbpasswd -a foobar

In your local machine:

Mount the foobar project directory, enter your samba password here:

$ sudo mount -t cifs -o username=foobar,uid=1003,gid=1003 //10.10.10.1/foobar /tmp/foobar

Explanations command line above:

1003 is the user local id, you can check it by type:

$ id
uid=1003(mylocaluser) gid=1003(mylocaluser)

10.10.10.1 is the vagrant ip address

tmp/foobar is a mounted folder from original directory in vagrant


How to download and convert video from youtube to MP3 in terminal

So, I needed to download songs from youtube but not as a video but only audio. Then I went to this website to convert these video as usual. The website that I used to convert video from youtube was popped out ads that I didn’t like. I started to thinking why the hell that I need those websites anyway? just use the terminal instead.

$ youtube-dl --extract-audio --audio-format mp3 <youtube-url>

Arcanist cheatsheet

$ arc patch D123
$ git add .
$ git commit -am "update"
$ arc diff --update D123
$ arc land --revision D123

Update diff to master

$ git checkout master
$ git merge arcpatch-D123
$ git push

Make a diff from current working branch

$ git add.
$ git commit -am "update"
$ arc diff --update D123

Push to working branch without land

$ git add .
$ git commit -am "update"
$ git push origin lol-branch

Make a diff from working branch from the first update

$ git checkout lol-branch
$ git add.
$ git commit -am "update"
$ arc diff master

SSH tunneling to your secured database/RDS through bastion/jump server with forwarded port

$ ssh -f -N -v -t -L 5433:target_host:5432 user@jump_server
  • target_host is the host/database_server/RDS that you want to access that only can be accessed from jump _server or bastion if you’re using AWS
  • jump_server is the host that accessible from you and the only host that can access target_host
  • 5432 is local port (postgresql default)
  • 5433 is the forwarded host/database_server/RDS port that you can access through localhost
    What’s next?

    Afterwards, you should be able to get postgresql open with forwarded port through localhost (5433).

    Test the forwarded port using telnet:

    $ telnet localhost 5433
    

    or using netcat:

    $ nc -vz localhost 5433
    

Create partition in Linux that size larger than 2TB

Install parted:

sudo apt-get install parted

Use parted to create partition:

parted /dev/sdb

Inside parted cli, follow these steps:

(parted) mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) unit GB
(parted) mkpart primary 0.0GB 3000GB
(parted) print

Format the filesystem we created, using mkfs and try to mount it to mount point:

mkfs.ext4 /dev/sdb1
mkdir /tes
mount /dev/sdb1 /tes

SSH tunneling to your secured server through bastion/jump server with forwarded port

This is a quick guide will show you how to open ssh tunnel to ssh into your target server that can only be accessed from jump server. So this is how to do it:

ssh -v -t -L 10443:localhost:20443 <jump_server> ssh -t -L 20443:localhost:443 user@<target_server>
  • jump_server is the host that accessible from you and the only host that can access target_server
  • target_server is the host that you want to access that only can be accessed from jump _server or bastion if you’re using AWS
  • 10443 is the forwarded port that you can access to SSH to target_server

So, here is the example:

ssh -v -t -L 10443:localhost:20443 123.456.1.1 ssh -t -L 20443:localhost:443 user@10.1.1.1
  • 123.456.1.1 is my jump_server that I can only access to access target_server
  • 10.1.1.1 is the target_server

And try it out, see the magic for yourself! after the last command above executed, you will inside your target_server and 10443 port is open from your localhost.

target_server~$

If you want to just have your SSH session running in background and you want to SSH it by yourself, just try this command:

ssh -f -N -v -t -L 10443:localhost:20443 123.456.1.1 ssh -t -L 20443:localhost:443 user@10.1.1.1

if you want to remove the logs (disable verbose mode) when you logging in, just remove the “-v”

SSH to localhost with port 10443, to access your target_server

$ ssh localhost 10443

Magic!