How to Scan Images Remotely

Hi folks,

Today I’ll briefly discuss a nice and easy way to scan images remotely. Suppose you have your multifunction printer or scanner hooked up to an Ubuntu server via a USB cable and you need to quickly scan a document while using a remote machine. How can you go about it? It’s easy. Just use the scanimage command over SSH. There’s an API called SANE (Scanner Access Made Easy) that provides a standard way to access raster image scanners [1]. SANE supports Windows, Linux, UNIX and OS/2. scanimage belongs to the SANE package and is available on Ubuntu by default.

First, log in to the server via SSH.

Next, turn on your printer/scanner and insert the document you wish to scan.

Next, run the following command:

scanimage --format=tiff ><your-file>.tiff

This should fire up your printer/scanner, scan the image and save the result in tiff format. From there you can transfer the output file to your machine for use.

Note that there are alternative ways to achieve this, e.g. by setting up a SANE daemon (saned) on your scanner server and then setting up a SANE client for Ubuntu or using TWAIN for Windows and Mac OS, thus allowing you to use compatible scanner software on the client [2].

Sources

  1. Scanner Access Now Easy – Wikipedia, the free encyclopedia. https://en.wikipedia.org/wiki/Scanner_Access_Now_Easy
  2. SaneDaemonTutorial – Community Help Wiki. https://help.ubuntu.com/community/SaneDaemonTutorial

How to view all programs listening on a specific port

In this post I discuss how to check what program is listening to a port on Ubuntu.

The command to use is

netstat -anp <port number> 

The “a” option means that all sockets should be shown, both listening and non-listening ones. The “n” option means numeric. By default netstat translates ports to their service name, making it more difficult to search ports by number. This option solves that. Finally, the “p” option shows the PID and name of the program so that you can tell exactly what’s listening to a port.

How to disable Root Login via SSH on Ubuntu

Disabling root access via SSH is a good security measure for any public-facing web server. This is because some hackers targeting linux servers know that there’s always a root user and often try to gain access to a server using brute force for that user. So here’s how to disable root login via SSH on ubuntu.

First, make sure there’s at least one other user with sudo privilege. If none exists, create one with the command:

sudo adduser <someuser>

sudo adduser <someuser> sudo

Next, edit /etc/ssh/sshd_config using your favourite editor.

Find the line:

PermitRootLogin yes

and change it to

PermitRootLogin no

Save and close the file.

Restart SSH daemon using the command

sudo service ssh restart

How to track Process Launches in Linux

Suppose you want to know what processes get launched at a given time on your Linux box like Ubuntu, you can use Auditd. Run the following commands.

apt-get install auditd
auditctl -a task,always
ausearch -i -sc execve

Sources

logging – How can I log all process launches in Linux – Super User. http://superuser.com/questions/222912/how-can-i-log-all-process-launches-in-linux

How to use Screen

Screen is a handy tool for creating SSH sessions that withstand network failures as well as for making SSH terminals containing multiple sessions.

To start a screen session use the command:

screen

You can also give the session a name using the command

screen -S <session name>

To detach from a running screen session use the command:

Ctrl+A d

To list screen sessions use the command:

screen -ls

To resume a screen session use the command:

screen -r

Sources

How To Use Linux Screen. https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/

How to prevent execessive scraping on Website on Ubuntu Server

Add rules as follows:

iptables -A INPUT -p tcp --syn --dport 80 -m connlimit\
 --connlimit-above 15 --connlimit-mask 32 -j REJECT \
 --reject-with tcp-reset 

This will reject connections above 15 from one source IP.

iptables -A INPUT -m state --state RELATED,ESTABLISHED \
-m limit --limit 150/second --limit-burst 160 -j ACCEPT  

In this 160 new connections (packets really) are allowed before the limit of 150 NEW connections (packets) per second is applied.

Note: if your server runs UFW (Uncomplicated Firewall), then you shouldn’t run the commands directly. Instead, you need to replace INPUT with ufw-before-input in each line and put the lines in the file /etc/ufw/before.rules. Afterwards, restart UFW using the following command:

sudo service ufw restart

Source

Limit max connections per IP address and new connections per second with iptables – Unix & Linux Stack Exchange. http://unix.stackexchange.com/questions/139285/limit-max-connections-per-ip-address-and-new-connections-per-second-with-iptable

How to remove all iptables rules

Create a file /root/fw.stop with the following content:

#!/bin/sh
echo "Stopping firewall and allowing everyone..."
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

Make it executable and then run it on the terminal.

Source: http://www.cyberciti.biz/tips/linux-iptables-how-to-flush-all-rules.html