Linux

SSH

Setting up SSH server on Ubuntu Server

This is the steps you need to do in order to get the SFTP up and running. In this case we will add userX to access the SFTP and when userX log on to the server the only folder that can be accessed is the one called root_folder.

# SFTP with chroot, http://www.debian-administration.org/articles/590

# Create a Group for the restricted accounts (only once)
$ sudo groupadd sftponly

# Create user with home directory and set users shell to /bin/false
$ sudo useradd userX -m -s /bin/false

# Set a password for the user
$ sudo passwd userX

# Change the users primary group to sftponly
$ sudo usermod -g sftponly userX

# The directory in which to chroot() must be owned by root
$ sudo chown root:root /home/userX

# Create upload directory with write access
$ sudo mkdir /home/userX/upload
$ sudo chown root:sftponly /home/userX/upload
$ sudo chmod 770 /home/userX/upload

# Create mount point for directory to share
$ sudo mkdir /home/userX/root_folder
$ sudo chown root:sftponly /home/userX/root_folder
$ sudo chmod 750 /home/userX/root_folder

# Create .ssh directory
$ sudo mkdir /home/userX/.ssh
$ sudo chown root:sftponly /home/userX/.ssh
$ sudo chmod 710 /home/userX/.ssh

# Mount root_folder directory to chroot directory (works as a virtual directory)
$ sudo nano /etc/fstab

/folder/to/be/mounted /home/userX/root_folder none bind 0 0

# Refresh fstab (mount)
$ sudo mount -a

# Paste public key of userX in authorized_keys
$ sudo nano /home/userX/.ssh/authorized_keys

# Protect authorized keys
$ sudo chown root:sftponly /home/userX/.ssh/authorized_keys
$ sudo chmod 640 /home/userX/.ssh/authorized_keys

# Configuring OpenSSH
$ sudo nano /etc/ssh/sshd_config

# Add:
subsystem sftp internal-sftp

AllowUsers userX userY userZ

Match group sftponly
ChrootDirectory /home/%u
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

# Restart the SSH Server
$ sudo service ssh restart

Securing your public SSH server

When you finally have your SFTP server up and running you need to secure it. Here's a guide with many tips. Top 20 OpenSSH Server Best Security Practices

SQL/T-SQL

SQL Server Management

Manage backups on your MS SQL Server

Managing backups on your SQL Server is really important and there are several ways of doing this. I found a job created by Ola Hallengren that does this in an excelent way. The script creates FULL, DIFF and LOG backup and you can customize the script in many ways. This is also what I've been using professionally when setting up and administrating backup jobs on MS SQL.

The script is free of use and the author keeps it up to date. However, if the script has moved since this was written, here is a local file for you to download: MaintenanceSolution.sql