Rsync to AWS EC2 Using .PEM key

The standard AWS EC2 instances support using a .PEM key to log in, instead of a more common SSH username/password combination. If you want to use Rsync to transfer data from your local machine to an AWS EC2 instance you will need to change the Rsync command to be something like this:

rsync -rave "ssh -i PEMKEYFILE.pem" /path/to/local/files/* ec2-user@EC2_INSTANCE_HOSTNAME:/path/to/remote/files

For simplicities sake I ensured that I was in the directory where the .pem key was saved, but you can adjust the command to give the path to your key file.

Beyond this it’s just like regular Rsync, so just follow the on-screen commands and you get secured file transfer between your local machine and your remote AWS EC2 instance



Command ‘ls’ output numerical chmod permissions

it almost can …

ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) *2^(8-i));if(k)printf("%0o ",k);print}'


stat -c "%a %n" *

Also, you can use any filename or directory name instead of * to get a specific result.

On Mac, you can use

stat -f '%A %N' *


Disable & remove virtual host website entry in Apache

You can list the currently enabled websites if you want to check the name:

$ ls /etc/apache2/sites-enabled
000-default.conf my-website.conf

Disable virtual host entry
Let’s assume we’d like to disable my-website.conf. To disable this virtual hosts entry, we issue the following command to Apache (note the exclusion of the .conf extension from the virtual host name):

$ sudo a2dissite my-website

You can confirm this has disabled the website by checking that the site is no longer listed in the enabled sites directory:

$ ls /etc/apache2/sites-enabled

You’ll then need to reload Apache for the changes to take effect:

$ sudo service apache2 reload

Remove virtual host entry

Wanna go the whole nine yards?

If you no longer need the virtual host configuration file, remove that too. First double check what it’s called by listing out the available websites:

$ ls /etc/apache2/sites-available
000-default.conf my-website.conf

Note that this is a different location to /etc/apache2/sites-enabled, from earlier.

Remove the config file you no longer need:

$ rm /etc/apache2/sites-available/my-website.conf

You may also want to backup then remove any website files residing in the /var/www directory, for example:

$ cd /var/www
$ tar czf my-website.tar.gz my-website
$ rm -r my-website

Finish up by copying the backup to somewhere safe and then go ahead and delete it from the server to free up some space.

List all IP addresses connected to linux server

ด้านล่างนี้เป็นคำสั่ง Unix เพื่อแสดงรายการที่อยู่ IP ทั้งหมดที่เชื่อมต่อกับเซิร์ฟเวอร์ของคุณบนพอร์ต 80

netstat -tn 2>/dev/null | grep :80 | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -nr | head

เอาท์พุท – การเชื่อมต่อโดยใช้ IP จากสูงสุดไปต่ำสุด


คำสั่งนี้จะเป็นประโยชน์ในการตรวจสอบว่าเซิร์ฟเวอร์ของคุณอยู่ภายใต้การโจมตีหรือไม่ให้เส้นทางเหล่านั้นเป็นโมฆะ อ่านนี่


connecting to amazon aws linux server by ssh on mac

You’ll want to put the keypair in {your home directory}/.ssh . If that folder doesn’t exist, create it. Once you put the keypair in there you have to change the permissions on the file so only your user can read it. Launch the terminal and type

chmod 600 ~/.ssh/

That limits access to the file, and then to limit access to the folder type

chmod 700 ~/.ssh

You have to limit the access because the OpenSSH protocol won’t let you use a key that other’s can view.

Then to log into your instance, from the terminal you would enter

ssh -i /.ssh/ ec2-user@


Ubuntu: mongo Failed message about LANG

When you call “mongo” and found this message.

$ mongo

Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_* environment variables are set correctly.

You can fix by, At the command prompt:

export LC_ALL=C

and then try again. If that doesn’t work, you may need to edit:

sudo vi /etc/default/locale

and set


to your preferred settings. As an example:


ทดสอบ server ด้วย ApacheBench

ab -n  -c  :

-n คือ จำนวนครั้งในการทดสอบ (Number of requests)
-c คือ การส่งทดสอบพร้อมๆ กัน (concurrency)


$ ab -n 100 -c 20
This is ApacheBench, Version 2.3 <$Revision: 1706008 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licensed to The Apache Software Foundation,

Benchmarking (be patient).....done

Server Software:        nginx/1.4.6
Server Hostname:
Server Port:            80

Document Path:          /lcc_live/event/132/progress
Document Length:        193 bytes

Concurrency Level:      20
Time taken for tests:   13.233 seconds
Complete requests:      100
Failed requests:        1
   (Connect: 0, Receive: 0, Length: 1, Exceptions: 0)
Non-2xx responses:      100
Total transferred:      41897 bytes
HTML transferred:       19126 bytes
Requests per second:    7.56 [#/sec] (mean)
Time per request:       2646.506 [ms] (mean)
Time per request:       132.325 [ms] (mean, across all concurrent requests)
Transfer rate:          3.09 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        4    8   1.5      8      10
Processing:   532  702 1203.1    604   12609
Waiting:      532  702 1203.2    604   12609
Total:        537  709 1203.3    613   12619

Percentage of the requests served within a certain time (ms)
  50%    613
  66%    614
  75%    614
  80%    614
  90%    614
  95%    615
  98%    615
  99%  12619
 100%  12619 (longest request)


LAMP on DigitalOcean upgrade php to php7.0

Start with add repositories

sudo add-apt-repository ppa:ondrej/php

but if you have some error about UTF-8 fix by

$ locale-gen en_US.UTF-8
$ export LANG=en_US.UTF-8
$ export LC_ALL=en_US.UTF-8
$ sudo add-apt-repository ppa:ondrej/php

and update apt-get

$ apt-get update && apt-get -y upgrade

Install New PHP Versions

$ sudo apt-get install php7.0

install apache mod package with

$ sudo apt-get install libapache2-mod-php7.0

Now I could run sudo a2dismod php5 for disable php5 and enable php7 with.

$ sudo a2dismod php5 
$ sudo a2enmod php7.0
$ sudo service apache2 restart

test with phpinfo() and end…

Command “traceroute” ดูเส้นทางไปยัง Server

traceroute คือ utility ที่เป็น Command line สำหรับ linux และ mac โดยจะเป็นคำสั่งที่ใช้ในการตรวจสอบเส้นทางจากเครื่อง com ของเราไปยังเว็บไซต์ปลายทางที่ต้องการเชื่อมต่อ

com1:~ mac$ traceroute
traceroute: Warning: has multiple addresses; using
traceroute to (, 64 hops max, 52 byte packets
1 ( 5.119 ms 5.636 ms 5.129 ms
2 ( 7.104 ms 6.899 ms 4.881 ms
3 ( 7.225 ms 36.025 ms 7.043 ms
4 ( 7.332 ms ( 8.536 ms ( 9.240 ms
5 ( 7.449 ms ( 17.092 ms 8.269 ms
6 ( 8.755 ms 14.974 ms ( 24.174 ms
7 ( 9.153 ms 11.442 ms 10.466 ms
8 ( 10.901 ms 9.480 ms 12.259 ms
9 ( 10.176 ms 11.244 ms 11.550 ms
10 ( 10.632 ms !Z 14.678 ms !Z 13.005 ms !Z