Raspberrypihelp

Tutorials for your Raspberry Pi.

Category: Tutorials (page 1 of 2)

Raspberry Pi SSH security – Fail2ban

fail2ban

 

Raspberry Pi SSH security – Fail2ban

There are a lot of shady people on the internet, scanning IP ranges for vulnerable machines/raspberry pi’s.
With a simple program called Fail2ban you can kick out the bruteforcers.
After 6 failedssh login’s the IP of the client will be blocked by default for 10 minutes.
Your raspberry pi is a lot safer now!

How to:

sudo apt-get update
[ENTER]
sudo apt-get install fail2ban
[enter]

 

Now fail2ban is installed! Easy isn’t it ?

You can change settings @ /etc/fail2ban/jail.conf
1st picture are the common settings, 2nd picture is specific for SSH.

 

fail2ban1

fail2ban2

 

Have fun!

Raspberry Pi Mount External Harddisk

Harddisk in my case: Normal NTFS formatted.

Connect the hard disk on your Raspberry Pi.

Login with putty, or open a termal.

sudo blkid
 [enter]

You see the hard disk name and his location. Something like /dev/sdxX before it. Remember the /dev/sdxX.

Now make a new folder on your pi.
Example: /home/raspberrypi/hardiskmount/

mkdir /home/raspberrypi/hardiskmount/

now typ:

sudo nano /etc/fstab

Add a new rule:

/dev/sdX /home/raspberrypi/hardiskmount/ ntfs default 0 0

Change the X to your own number from the sudo blkid commando on the first step.

Save the file, and close it. (Control + x)

sudo mount -a
 [enter]

 

Now navigate to the /home/raspberrypi/hardiskmount/ folder, to use your mounted harddrive!

 

Have fun!

Raspberry Pi Nagios Monitor System

Nagios

 

Nagios monitor system Raspberry Pi

With Nagios you can:

  • Monitor your entire IT infrastructure
  • Spot problems before they occur
  • Know immediately when problems arise
  • Share availability data with stakeholders
  • Detect security breaches
  • Plan and budget for IT upgrades
  • Reduce downtime and business losses

How To install Nagios on the raspberry pi?

First:
Update + Upgrade your rasperry pi:

sudo apt-get update
[ENTER]
sudo apt-get upgrade
[ENTER]
sudo apt-get install nagios3
[ENTER]

After a while you get this screen, enter a password.

Nagios1

All done? You can access Nagios in your webbrowser:

http://RASPBERRYPIIPADRES/nagios3

Nagios2

 

Have fun!

Raspberry Pi Webserver

Webserver-tut

 

Host your own website on the raspberry pi? Yes you can!

You will install the following programs:

  • nginx
  • MySQL
  • PHP5-fpm
  • phpMyAdmin
  • ImagIck
  • vsftpd
apt-get update
[enter]
apt-get upgrade
[enter]

Now you are up to date 🙂

 

Install the mysql server:

sudo apt-get install mysql-server
[ENTER]

You will get a screen for entering the mysql password, enter a long and secure password!

 

sudo apt-get install nginx
[ENTER]
sudo service nginx start
[ENTER]
sudo apt-get install php5-fpm
[ENTER]
sudo apt-get install php5-imagick
[ENTER]
sudo nano /etc/php5/fpm/php.ini

Change the rule “upload_max_filesize = 2M” to

"upload_max_filesize = 10M"

Add this rule at the  Dynamic Extensions section:

extension=imagick.so

Webserver-tut2

Control + X to close/save the file.

sudo apt-get install phpmyadmin
[ENTER]

At the webserver selection screen press “TAB” on your KEYBOARD
[ENTER] Don’t select apache or lighttpd!

If you get the screen if you want db-config,  choose “Yes”.

Webserver-tut3

The following step is entering your MySQL password, and set a password for phpMyAdmin.

Webserver-tut4

 

Done?

sudo service php5-fpm restart
[ENTER]
sudo mkdir /srv/www
[ENTER]
sudo chown -R YOURUSERNAME:www-data /srv/www
[ENTER]
sudo chmod -R 755 /srv/www
[ENTER]
mkdir /srv/www/example.com
[ENTER]
cd /srv/www/example.com
[ENTER]
mkdir logs
[ENTER]
nano logs/access.log (Just make the file, and close it)
[ENTER]
nano logs/error.log (Just make the file, and close it)
[ENTER]
mkdir public

(Change example.com with your own site-name)

sudo nano /etc/nginx/sites-available/example.com
[ENTER]

Add the following info in the file:

 

server {
    server_name example.com 192.168.1.116;
    access_log /srv/www/example.com/logs/access.log;
    error_log /srv/www/example.com/logs/error.log;
    root /srv/www/example.com/public/;
    location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /srv/www/example.com/public$fastcgi_script_name;
    }
    location /phpmyadmin {
        root /usr/share/;
        index index.php index.html index.htm;
        location ~ ^/phpmyadmin/(.+\.php)$ {
            try_files $uri =404;
            root /usr/share/;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include /etc/nginx/fastcgi_params;
        }
        location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
            root /usr/share/;
        }
    }
    location /phpMyAdmin {
        rewrite ^/* /phpmyadmin last;
    }
}

 

sudo ln -s /etc/nginx/sites-available/yoursitename /etc/nginx/sites-enabled/yoursitename
[ENTER]
sudo service nginx restart
[ENTER]
nano /srv/www/example.com/public/index.php

Add the following:

<?php phpinfo(); ?>

Control + x to close/save the file.

http://YOURRASPBERRYPIIPADRES

Have fun!

Raspberry Pi File Transfer – WinSCP

Easy transferring your files from and to your Raspberry Pi, without setting up a FTP server!

Download WinSCP here: http://winscp.net/eng/download.php

If you boot wheezy-raspbian for the first time, enable SSH on the raspi-config screen. Or if you want to get into the config screen again.
Typ:

 sudo raspi-config
 [ENTER]

WinSCPtut

Install Winscp, open it, and enter your Raspberry Pi details.

File protocol: SFTP or SCP. It dont care 🙂
Hostname = Your raspberry pi IP adres
Username: Your raspberry pi username
Password: The password of your raspberry pi username.

 

WinSCPtut-2

 

Once you are logged in, the left side of the screen is your local computer. The right side is your Raspberry pi!
Drag files from left to right or from right to left to copy files.

WinSCPtut-3

 

Have fun!

Raspberry Pi Screen (Keep your processes running after disconnect)

Raspberry Pi  Screen Tutoria

“Screen” is a program to run one or multiply SSH connections in the background.  The session will keep alive, even if you close your SSH connection.

Install screen:

sudo apt-get install screen
[Enter]

Now you have Screen installed.

Typ:

Screen
[Enter]

Now you see a screen like this:

screenprogram1

 

Press the spacebar / Enter key / Return key to move on.

This screen looks like the same as a normal putty connection. But you are in the “screen” program.

Screen command list:

Ctrl + A + C:  Create a new SCREEN session.
Ctrl + A + N:  Switch to the Next screen session.
Ctrl + A + P:  Switch to the Previous screen session.
Ctrl + A + D:  Detaches a screen session (without killing the processes in it – they continue).

 

To close a Screen session typ:

exit
[ENTER]

 

If you are in the normal SSH session, and you want to start a virtual screen session with the name “thevirualsession”

screen -S thevirualsession.

Back to the normal ssh session and keep the virtual session alive (Detache):

Control + a + d

If you are in the normal SSH connection, and you want to see all the current screens:

screen -ls
[ENTER]

i have 1 “Screen” session open:

screenprogram2

 

And now how to switch to the “Screen” session? Typ:

screen -r 2494.pts-0.raspberrypi
[enter]

Have fun!

Raspberry Pi Hanewin NFS share KODI – XBMC

Hanewin NFS share – How to setup a nfs share for your Raspberry Pi XBMC mediacenter.

HANEWIN Downloads (Trial) Full non version costs around €19,00)

This has been used successfully on Windows XP,  Vista, Windows 7, Windows 8. Windows 8,1 Windows 10
First:  Add the following ports in your “allow” list, in Windows Firewall.

Windows firewall -> Advaned Settings
—/Inbound Rules -> New Rule -> Port -> TCP ->Specific local port: 1058, 111, 2049
Follow the same stepts for UDP.

And do the same for outbound rules (TCP & UDP)

inbound AND outbound!
TCP/UDP: 1058
TCP/UDP: 111
TCP/UDP: 2049

Start Hanewin NFS server and use these settings:

Hanewin1

Hanewin2

Hanewin3

 

Edit exports file
My exports file looks like this:

G:\Downloads\movies -readonly -public
F:\Downloads\movies -readonly -public

As you see i use the -readonly & -public option, for a full list of options use this link to the original Hanewin website.

Save the file and hit the “Restart Server” button.

 

Now on the XBMC side: Add a new NFS share -> click -> clack -> You are done!

You can also use a free nfs server, like: FreeNFS, But i don’t have experience with.

Raspberry Pi Owncloud (Dropbox Clone)

Owncloud

 

Owncloud is like dropbox, but then local and hosted on your OWN Raspberry Pi!

Features of Owncloud:
Acces your data
Sync your data
share your data
Calendar share
And more!

 

Here we go!

sudo aptitude install nginx php5-fpm php5-sqlite php5-gd
[ENTER]
cd /etc/nginx/sites-available
[ENTER]
sudo nano owncloud.vhost
[ENTER]

Copy this txt info the owncloud.vhost file

# redirect http to https.
#server {
#  listen 80;
#  server_name owncloud.example.org;
#  rewrite ^ https://$server_name$request_uri? permanent;  # enforce https
#}
# owncloud (ssl/tls)
server {
  #listen 443 ssl;
  listen 80;
  #ssl_certificate /etc/nginx/certs/server.crt;
  #ssl_certificate_key /etc/nginx/certs/server.key;
  #server_name localhost;
  root /usr/share/nginx/www/owncloud;
  index index.php;
  client_max_body_size 1000M; # set maximum upload size
  # deny direct access
  location ~ ^/(data|config|\.ht|db_structure\.xml|README) {
    deny all;
  }
  # default try order
  location / {
    try_files $uri $uri/ @webdav;
  }
  # owncloud WebDAV
  location @webdav {
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #fastcgi_param HTTPS on;
    include fastcgi_params;
  }
  # enable php
  location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #fastcgi_param HTTPS on;
    include fastcgi_params;
  }
}

sudo ln -s /etc/nginx/sites-available/owncloud.vhost /etc/nginx/sites-enabled/
[ENTER]
sudo nano /etc/php5/fpm/php.ini

ADD THE FOLLOWING:

extension=sqlite.so
extension=zip.so
extension=json.so
extension=xmlrpc.so
extension=curl.so
extension=gd.so

Hit control + X to close/save the file.

Now download Owncloud.
Check the website for the newest release: https://owncloud.org/install/#instructions-server

cd /home/pi
[ENTER]
wget https://download.owncloud.org/community/owncloud-9.0.0.tar.bz2
[ENTER]
sudo tar -xjf owncloud-9.0.0.tar.bz2

(CHANGE THE 9.0.0 TO THE CURRENT VERSION)

 

sudo chown -R www-data:www-data owncloud
[ENTER]
sudo mkdir /usr/share/nginx/www/owncloud
[ENTER]
sudo mv owncloud /usr/share/nginx/www/
[ENTER]
sudo /etc/init.d/nginx start
[ENTER]
sudo nano /etc/php5/fpm/php.ini

And change the

upload_max_filesize = 2M (from 2MB to the max size you want)
post_max_size = 6M (To the size you want)

 

Reboot your raspberry pi:

Sudo reboot now
[ENTER]

Now acces the Owncloud page! http://RASPBERRYPIIPADRES

 

Owncloud-2

Raspberry Pi Ambilight – Boblight – XBMC

Boblight

 

Raspberry Pi Ambilight – Boblight – XBMC

This guide will tell you how to get Boblight & Raspbmc & xbmc running on the same Raspberry Pi
to make an awesome media centre experience for ~ €50!

The Home of PiBob! http://pibob.nadnerb.co.uk/

Raspberry Pi Bittorrent Sync – Bitsync

BTsync

 

Bitsync.

With Bitsync you can sync folders/files aross computers, tablets, phones., like Dropbox.  But your data with bitsync is private and secure on your own harddrives, data carrier.

Pro’s of Bitsync:

  • All your data in own hands, no 3th party “cloud”
  • The only size limitation is your own hard drive. Files can be 1kb, or even 1TB!

Con’s:

  • If you have 2 devices. 1 PC and 1 smartphone. If the pc is off the smartphone can’t sync because the PC is off.

That’s why we use the Raspberry pi. It’s always on with low power consumption.

How to install Bitsync on the Raspberry Pi:

sudo nano /etc/apt/sources.list.d/btsync.list

past following lines:

deb http://debian.yeasoft.net/btsync wheezy main contrib non-free
deb-src http://debian.yeasoft.net/btsync wheezy main contrib non-free

Control + x to close/save the file.

sudo apt-get update
sudo apt-get install btsync

Config: Default Sync instance? Yes.

BTsync-1

Port nr? Pick something random: for example: 45454
BTsync-2

 

Portmapping UPNP: Own choice, If you don’t use UPNP you must manually open the port in your modem/router. For now we choose YES.

BTsync-3

 

Bandwidth: 0 = No limit.

BTsync-4

 

 

Upload Bandwidth:

BTsync-5

 

Web interface: Leave it. Hit enter key.

BTsync-6

 

Web interface port: 8888

BTsync-7

 

Specify a password for the interface:

BTsync-8

 

Browse to:

http://RASPBERRYPI-IP-ADDRESS:8888/

Add a folder, Generate a private key, You will need enter this key on your smartphone/pc to sync with the just created folder.

 

BTsync-9

BTsync-10

 

How to stop Btsync?

sudo service btsync stop

Bit torrent sync will auto start on raspberry pi boot up.

 

Have  fun!

 

Older posts

© 2016 Raspberrypihelp

Theme by Anders NorenUp ↑