Tag

cc nano

My Favorite Backup Method DD BZIP SSH Script

By | Featured, Sample Work | No Comments

Backup today can be a PITA.  It takes too long, and too much work to automate.  That’s what makes this single line backup script one of my favorites. It creates a compressed DD image a remote server in the form of a BZ2 archive. This command is run locally from the machine you want to backup.

Let’s begin:
First, create your file
[raw]nano xf[/raw]

Inside xf, paste the following:
[raw] #!/bin/bash
dd if=/dev/vda1 of=/dev/stdout bs=1M | bzip2 | ssh root@myhost.com “cat – > /home/backups/Live.img.bz2”
[/raw]

Let’s break this down, so you can create your own command!

First, start by doing a [raw]df -a[/raw] to determine the name of your disk, replacing /dev/vda1 with the disk you want to backup.

Second, change root@myhost.com to your remote server. For best practices you should exchange SSH keys so there is no password prompt. See this tutorial here to exchange keys.

Finally, change /home/backups/Live.img.bz2 to the destination directory and filename you would like on the remote server.

Run the script in a shell to test, and finally automate.

Be sure to make your script executable by running [raw]chmod +x[/raw] after creation. To run in the background, install [raw]apt-get install nohup[/raw]. This will allow you to start your backup script in the background, allowing it plenty of time to execute. [raw]nohup ./scriptname &[/raw] will run the script as a daemon.

vsftpd Ubuntu 12.04 Install and Add Secure User

By | Sample Work | No Comments

60 Second Install. 3 – 2 – 1 – GO!

[raw]sudo apt-get install vsftpd[/raw] [raw]sudo nano /etc/vsftpd.conf[/raw]

Uncomment the Following:
[raw] write_enable=YES
local_umask=022
[/raw]

Add to end of the file:

[raw]

# the list of users to give access
userlist_file=/etc/vsftpd.userlist
# this list is on
userlist_enable=YES
# It is not a list of users to deny ftp access
userlist_deny=NO[/raw]

Setup the user, replace /path/to/your/dir

[raw]useradd -d /path/to/your/dir -s /usr/sbin/nologin ftpuser
passwd ftpuser
chown -R ftpuser /path/to/your/dir
chmod 775 /path/to/your/dir
[/raw]

Add new user to vsftpd

[raw] nano /etc/vsftpd.userlist[/raw]

Add “ftpuser” to this file

[raw]nano /etc/shells[/raw]

Add “/usr/sbin/nologin” to this file

[raw]addgroup ftpusers

sudo usermod -Gftpusers ftpuser

service vsftpd restart
[/raw]

BONUS:

You can chroot users by uncommenting this section of vsftpd.conf file:

[raw] chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
[/raw]

Add “ftpuser” to this file

[raw]nano /etc/vsftpd.chroot[/raw]

Questions?  Hit up the comments.