30 October 2015

Akses SSH Router atau VPS Linux dengan RSA Authentication ( Tanpa Password )

Akses router/VPS dengan menggunakan WinSCP sering saya lakukan. Melalui WinSCP , saya bisa melakukan akses SSH dengan cara klik icon Putty yang tersedia. Biasanya di minta password untuk melanjutkan. Nah agar tidak perlu lagi mengetik password saat ingin mengakses SSH bisa memakai RSA keys untuk authentication-nya.

Setelah google sana-sini ternyata tidak begitu susah untuk melakukannya.


Mula-mula kita buat keys dengan bantuan Putty Key Generator (Puttygen).


Contoh :

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAnW7VJEPpVnjjIAbPQGrYmUYMQSxDxeb+oeyvQkBpJLiza1UZX+qA7hIT/nfjTirn6nAbFnabcSiqXpmjEtcpNG2Fo11kTBj60btC0unqbEAK8yYjSo1sgNq/tGnU00Ez9/2rzv5ospbx5QJUpMhEffNYlyQY3Q0zFxxmpUB4GgyDe9clQe336sj+2REDveDvNf+rgRFg54XCobFkW0LIA1NN2Tq0RX8zbVx310EzT1mBxm4Jl5ZqnasdFyNFXgxoqYalJwc/GFOQm1aSDeHGVoEQb1ViaPRa0G+M36eFGKr9XM6OZD69OG2Eenj7Nm4MExvlXkiyFgLJrvEDTaCleQ== rsa-key-20151030

Ini disebut dengan Public Key dan harus di copy ke /etc/dropbear/authorized_keys routernya OpenWRT. Ingat cukup copy-kan bagian :

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAnW7VJEPpVnjjIAbPQGrYmUYMQSxDxeb+oeyvQkBpJLiza1UZX+qA7hIT/nfjTirn6nAbFnabcSiqXpmjEtcpNG2Fo11kTBj60btC0unqbEAK8yYjSo1sgNq/tGnU00Ez9/2rzv5ospbx5QJUpMhEffNYlyQY3Q0zFxxmpUB4GgyDe9clQe336sj+2REDveDvNf+rgRFg54XCobFkW0LIA1NN2Tq0RX8zbVx310EzT1mBxm4Jl5ZqnasdFyNFXgxoqYalJwc/GFOQm1aSDeHGVoEQb1ViaPRa0G+M36eFGKr9XM6OZD69OG2Eenj7Nm4MExvlXkiyFgLJrvEDTaCleQ==

Jadi hilangkan bagian rsa-key-20151030

Lalu Save Private Key-nya dalam bentuk file .ppk .
Buka WinSCP, di halaman login pilih Advanced -- SSH -- Authentication -- Private Key File. Arahkan di kolom yang tersedia ke file Private Key yang barusan kita save.



Sampai disini selesai langkah-langkahnya, tinggal di coba apakah sukses atau tidak.

Langkah-langkah diatas juga bisa diterapkan ke VPS yang saya pakai kebetulan Debian.

Mula-mula di enable dulu authentication menggunakan RSA di file /etc/ssh/sshd_config dengan cara hilangkan tanda pagar # di bagian depan :

#AuthorizedKeysFile %h/.ssh/authorized_keys

Restart ssh di VPS dengan perintah:
/etc/init.d/ssh restart

Kemudian buat file di /root/.ssh/authorized_keys dan di isi dengan hasil paste-kan Public Key seperti contoh diatas:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAnW7VJEPpVnjjIAbPQGrYmUYMQSxDxeb+oeyvQkBpJLiza1UZX+qA7hIT/nfjTirn6nAbFnabcSiqXpmjEtcpNG2Fo11kTBj60btC0unqbEAK8yYjSo1sgNq/tGnU00Ez9/2rzv5ospbx5QJUpMhEffNYlyQY3Q0zFxxmpUB4GgyDe9clQe336sj+2REDveDvNf+rgRFg54XCobFkW0LIA1NN2Tq0RX8zbVx310EzT1mBxm4Jl5ZqnasdFyNFXgxoqYalJwc/GFOQm1aSDeHGVoEQb1ViaPRa0G+M36eFGKr9XM6OZD69OG2Eenj7Nm4MExvlXkiyFgLJrvEDTaCleQ==

Lalu ulangi lagi prosedur save Private Key di WinSCP seperti diatas, dan semoga VPS pun bisa diakses SSH-nya tanpa perlu mengetik password lagi.

Inti sari nya :
Public Key copy ke Router/VPS
Private Key di pakai untuk Client


Selamat mencoba !!!

16 July 2015

Monitor Suhu dan Kelembaban memakai Ubidots

Grafik di atas menunjukkan suhu dan kelembaban di kamar saya.

Untuk menghasilkan grafik di atas saya memakai pengukur suhu DHT11 yang di akses melalui Arduino Pro Mini.
Kemudian data di kirim ke website Ubidots melalui router MR3020 yang sudah di flash dengan OpenWRT.

Okay tanpa basa-basi lagi akan saya sharingkan beberapa hal berikut.

Sketch Arduino - nya :

//
// FILE: dht11_test1.pde
// PURPOSE: DHT11 library test sketch for Arduino
//
//Celsius to Fahrenheit conversion
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
}
// fast integer version with rounding
//int Celcius2Fahrenheit(int celcius)
//{
// return (celsius * 18 + 5)/10 + 32;
//}
//Celsius to Kelvin conversion
double Kelvin(double celsius)
{
return celsius + 273.15;
}
// dewPoint function NOAA
// reference (1) : http://wahiduddin.net/calc/density_algorithms.htm
// reference (2) : http://www.colorado.edu/…/weather_stati…/Geog_site/about.htm
//
double dewPoint(double celsius, double humidity)
{
// (1) Saturation Vapor Pressure = ESGG(T)
double RATIO = 373.15 / (273.15 + celsius);
double RHS = -7.90298 * (RATIO - 1);
RHS += 5.02808 * log10(RATIO);
RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ;
RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ;
RHS += log10(1013.246);
// factor -3 is to adjust units - Vapor Pressure SVP * humidity
double VP = pow(10, RHS - 3) * humidity;
// (2) DEWPOINT = F(Vapor Pressure)
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558 - T);
}
// delta max = 0.6544 wrt dewPoint()
// 6.9 x faster than dewPoint()
// reference: http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity*0.01);
double Td = (b * temp) / (a - temp);
return Td;
}
dht11 DHT11;
‪#‎define‬ DHT11PIN 2
boolean ack = false;
void setup()
{
Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
}
void loop()
{
// Serial.println("\n");
int chk = DHT11.read(DHT11PIN);
/*
Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}
*/
// Serial.print("Humidity (%): ");
Serial.println((int)DHT11.humidity);
// Serial.print("Temperature (C): ");
Serial.println((int)DHT11.temperature);
delay(2000);
}
//
// END OF FILE
//
Di Router MR3020 -nya :
1. Edit /usr/bin/suhu.sh
#!/bin/sh
cat /dev/ttyUSB0 > /tmp/log.txt &
sleep 2
killall cat
api_key="b7adf5968db2140dcea136c458c4be4a6440a3ec"
deviceID="55a7382a7625422d983169d3"
deviceID2="5613482a7625ab22d983169a4"
value=`cat /tmp/log.txt | tail -n 1` ‪#‎post‬ data Suhu
value2=`cat /tmp/log.txt | head -n 1` #post data Kelembaban
‪#‎obtain‬ a token
my_token=`/usr/lib/lua/ubidots.lua -token $api_key)`
echo "Token: "$my_token
#post Temperature data to Ubidots
/usr/lib/lua/ubidots.lua "-post" $api_key $deviceID $value
sleep 1
#post Humidity data to Ubidots
/usr/lib/lua/ubidots.lua "-post" $api_key $deviceID2 $value2
2. Pakai cronjob jalankan script diatas setiap menit
* * * * * /usr/bin/ubidots.sh > /dev/null

Untuk tutorial lebih lengkap saya persilahkan menuju ke website : http://www.ediy.com.my/index.php/projects/item/121-ubidots-lua-openwrt-router-ubidots-real-time-data-monitoring .

Selamat mencoba !

21 February 2015

MR3020 + Webcam Logitech C170 + Motion = CCTV Sederhana

Kali ini akan saya sharingkan bagaimana cara membuat CCTV sederhana dengan menggunakan router dan webcam.

Peralatan yang saya gunakan:
1. Router TP-Link MR3020
2. Webcam Logitech C170
3. USB Hub Belkin 7 port
4. Flashdisk Kingston 8 GB

Referensi yang saya pakai ada di website :
http://sheldor.blogspot.com/2013/09/openwrt-based-video-recording-system.html
http://sheldor.blogspot.com/2013/09/openwrt-based-video-recording-system_10.html

Sesuai petunjuknya, mula-mula routernya di flash dengan OS OpenWRT dan di exroot.
Selanjutnya download file .rar berikut :
https://www.dropbox.com/s/bc417l2ty7sj9uv/Motion%2BFFMpeg.rar?dl=0


OS OpenWRT yang saya pakai adalah versi Attitude Adjustment. Versi Barrier Breaker seharusnya juga bisa dipakai.

Ekstrak file. rar yang telah di download tadi ke PC dan selanjutnya dengan menggunakan software Putty di transfer ke routernya.
Install semua file *.ipk - nya ke router dengan perintah di Putty :

opkg install *.ipk

Berikutnya adalah edit file konfigurasi aplikasi Motion nya yang ada di :
/etc/motion.conf  :

Thread 0
daemon = on
process_id_file = /var/run/motion/motion.pid
setup_mode = off
logfile = (not defined)
log_level = 4
log_type = all
videodevice = /dev/video0
v4l2_palette = 8
input = -1
norm = 0
frequency = 0
rotate = 0
width = 640
height = 360
framerate = 3
minimum_frame_time = 0
netcam_url = (not defined)
netcam_userpass = (not defined)
netcam_keepalive = off
netcam_proxy = (not defined)
netcam_tolerant_check = off
auto_brightness = on
brightness = 0
contrast = 0
saturation = 0
hue = 0
roundrobin_frames = 1
roundrobin_skip = 1
switchfilter = off
threshold = 5000
threshold_tune = off
noise_level = 32
noise_tune = on
despeckle_filter = (not defined)
area_detect = (not defined)
mask_file = (not defined)
smart_mask_speed = 0
lightswitch = 50
minimum_motion_frames = 2
pre_capture = 2
post_capture = 2
event_gap = 60
max_movie_time = 0
emulate_motion = off
output_pictures = off
output_debug_pictures = off
quality = 75
picture_type = jpeg
ffmpeg_output_movies = on
ffmpeg_output_debug_movies = off
ffmpeg_timelapse = 0
ffmpeg_timelapse_mode = daily
ffmpeg_bps = 200000
ffmpeg_variable_bitrate = 0
ffmpeg_video_codec = mpeg4
ffmpeg_deinterlace = off
use_extpipe = off
extpipe = (not defined)
snapshot_interval = 0
locate_motion_mode = off
locate_motion_style = redcross
text_right = %Y-%m-%d\n%T-%q
text_left = Logitech-C170
text_changes = on
text_event = %Y%m%d%H%M%S
text_double = on
exif_text = (not defined)
target_dir = /www/cctv
snapshot_filename = %v-%Y%m%d%H%M%S-snapshot
picture_filename = %v-%Y%m%d%H%M%S-%q
movie_filename = %Y-%m-%d--Jam-%H-%M-%S-Shot-%v
timelapse_filename = timelapse-tanggal-%d-%m-%Y
ipv6_enabled = off
stream_port = 0
stream_quality = 50
stream_motion = off
stream_maxrate = 3
stream_localhost = off
stream_limit = 0
stream_auth_method = 0
stream_authentication = (not defined)
webcontrol_port = 8081
webcontrol_localhost = off
webcontrol_html_output = on
webcontrol_authentication = (not defined)
track_type = 0
track_auto = off
track_port = (not defined)
track_motorx = 0
track_motorx_reverse = off
track_motory = 0
track_motory_reverse = off
track_maxx = 0
track_minx = 0
track_maxy = 0
track_miny = 0
track_homex = 128
track_homey = 128
track_iomojo_id = 0
track_step_angle_x = 10
track_step_angle_y = 10
track_move_wait = 10
track_speed = 255
track_stepsize = 40
quiet = on
on_event_start = (not defined)
on_event_end = (not defined)
on_picture_save = (not defined)
on_motion_detected = (not defined)
on_area_detected = (not defined)
on_movie_start = (not defined)
on_movie_end = (not defined)
on_camera_lost = (not defined)
video_pipe = (not defined)
motion_video_pipe = (not defined)
thread = No threads

Tinggal jalankan aplikasi dengan perintah :
motion

Aplikasi ini akan selanjutnya merekam video bila terdeteksi aktivitas dalam bentuk file *.avi . File video disimpan di router di folder /www/cctv

Contoh hasil rekaman adalah sebagai berikut :



Mula-mula saya sering mendapatkan rekaman video error seperti ini :


Ternyata solusinya cukup mudah tinggal edit file konfigurasi seperti diatas dengan :
lightswitch 50 .

Sekian dulu tutorialnya , semoga bermanfaat.