examples – Derek Demuro https://www.derekdemuro.com Software Engineer Sat, 12 Dec 2020 22:45:37 +0000 en-US hourly 1 160473225 LUKS Drive Encryption https://www.derekdemuro.com/2015/10/23/luks-drive-encryption/ https://www.derekdemuro.com/2015/10/23/luks-drive-encryption/#respond Fri, 23 Oct 2015 06:30:46 +0000 https://www.derekdemuro.com/?p=3241 Luks keys… and luks encrypted drives:

Warning: Always backup the LUKS header before performing any maintenance on the hard drive!.

How to backup the luks header:
Drive: /dev/sdb [Example]

Name: /tmp/mybackup [Example]

cryptsetup luksHeaderBackup $DRIVE --header-backup-file $NAME

Add a LUKS key:

Deckey: Would be your passphrase key for decrypting your drive [first key when setting up the encrypted drive].

Slot: Luks has 8 possible slots, so you have to tell it where to store the key, ranges from 0 to 7.

Keylocation: Store the key you want to use somewhere, and pass it’s path there. Example /tmp/mykey, this is the safest way.

echo $DECKEY | cryptsetup luksAddKey --key-slot $SLOT $DRIVE $KEYLOCATION

Remove a LUKS key:

Using specific passphrase:

cryptsetup luksRemoveKey $DRIVE

Using a kill-slot, you can now use any passphrase remaining on the header to kill it:

cryptsetup luksKillSlot $DRIVE $SLOT

In both cases, you input the passphrase; there’s no further confirmation. If you want to remove it programmatically:

echo [passphrase] | cryptsetup luksKillSlot|luksRemoveKey $DRIVE

Now you can backup the header, remove the key, add the key…

Restore backup header:

PathToBackup: format /tmp/backupfile

cryptsetup luksHeaderRestore $DRIVE --header-backup-file $PATHTOBACKUP

Drive will be now restored; watch out, if the wrong backup file is used, your data may be now scrambled eggs.

]]>
https://www.derekdemuro.com/2015/10/23/luks-drive-encryption/feed/ 0 3241
Installing SWFTools in Debian 7 https://www.derekdemuro.com/2014/10/20/installing-swftools-in-debian-7/ https://www.derekdemuro.com/2014/10/20/installing-swftools-in-debian-7/#respond Mon, 20 Oct 2014 06:44:24 +0000 https://www.derekdemuro.com/?p=3291 How to install PDF2SWF, PDFTools in Debian.

First you need the needed repositories.

wget https://download.savannah.gnu.org/releases/freetype/freetype-2.4.0.tar.gz
wget https://www.ijg.org/files/jpegsrc.v7.tar.gz
wget https://www.swftools.org/swftools-2013-04-09-1007.tar.gz
 
tar -zvxf swftools-2013*
tar -zvxf jpegsrc.v7
tar -zvxf freetype*
cd jpegsrc.v7
./configure
make
make install
cd freetype-2.4.0
./configure
make
make install
cd swftools-2013-04-09-1007
./configure
make
make install

modules/.././types.h:36:2: #error "no way to define 64 bit integer"
modules/.././types.h:39:2: #error "don't know how to define 32 bit integer"
modules/.././types.h:42:2: #error "don't know how to define 16 bit integer"
modules/.././types.h:45:2: #error "don't know how to define 8 bit integer"

The first solution.

ldconfig /usr/local/lib
./configure

Given that, not even then I got to install it, proceed and clone the master branch on Github, that seems to work perfectly fine.

So the solution I found somewhere:

apt-get install gcc g++ zlib1g-dev make libgif-dev
wget https://download.savannah.gnu.org/releases/freetype/freetype-2.4.9.tar.gz
tar xzvf freetype-*.tar.gz
cd freetype*
rm -f config.cache
ldconfig /usr/local/lib
LDFLAGS="-L/usr/local/lib" CPPFLAGS="-I/usr/local/include" ./configure
make
make install
cd ..
wget https://www.ijg.org/files/jpegsrc.v8d.tar.gz
tar xzvf jpeg*.tar.gz
cd jpeg*
rm -f config.cache
LDFLAGS="-L/usr/local/lib" CPPFLAGS="-I/usr/local/include" ./configure
make
make install
cd ..
wget https://www.swftools.org/swftools-0.9.1.tar.gz
tar xzvf swftools-*.tar.gz
wget ftp://ftp.foolabs.com/pub/xpdf/xpdf-3.03.tar.gz
mv xpdf-*.tar.gz swftools-*/lib/pdf
cd swftools-*
LDFLAGS="-L/usr/local/lib" CPPFLAGS="-I/usr/local/include" ./configure
make
make install
cd ..
rm -r jpeg*
rm -r swftools*
rm -r freetype*
]]>
https://www.derekdemuro.com/2014/10/20/installing-swftools-in-debian-7/feed/ 0 3291
du command, disk usage with style! https://www.derekdemuro.com/2014/02/27/du-command-disk-usage-with-style/ https://www.derekdemuro.com/2014/02/27/du-command-disk-usage-with-style/#respond Thu, 27 Feb 2014 06:48:26 +0000 https://www.derekdemuro.com/?p=3321 Disk usage: working with du command in linux.

Sometimes we need to work with disk usage in Linux terminals and work with files, such as finding the most critical files in the system for rogue backups or files or simply contraband.

Lets go with:

Find folder size in human readable [Gigs, Megs, Bytes…]

On the right we can see an example using du, with max-depth=1 [Meaning only the root].

du command

$ du -a
0   ./redhat/rh7
4   ./redhat
4   ./testfile.txt
0   ./linuxKernel
0   ./ubuntu/ub10
4   ./ubuntu
16  .

du human readable

$ du -ah
0   ./redhat/rh7
4.0K    ./redhat
4.0K    ./testfile.txt
0   ./linuxKernel
0   ./ubuntu/ub10
4.0K    ./ubuntu
16K .

du exclusion

du -cbha --exclude="*.txt"
0   ./redhat/rh7
4.0K    ./redhat
0   ./linuxKernel
0   ./ubuntu/ub10
4.0K    ./ubuntu
12K .
12K total

du custom display type.

$ du -cbha --time
0   2012-05-22 21:52    ./redhat/rh7
4.0K    2012-05-22 21:52    ./redhat
3   2012-06-18 19:23    ./testfile.txt
0   2012-05-22 21:52    ./linuxKernel
0   2012-05-22 21:52    ./ubuntu/ub10
4.0K    2012-05-22 21:52    ./ubuntu
13K 2012-06-18 19:23    .
13K 2012-06-18 19:23    total
]]>
https://www.derekdemuro.com/2014/02/27/du-command-disk-usage-with-style/feed/ 0 3321
Rsync and SCP file transfer wiki using the terminal. https://www.derekdemuro.com/2013/07/20/rsync-and-scp-file-transfer-wiki-using-the-terminal/ https://www.derekdemuro.com/2013/07/20/rsync-and-scp-file-transfer-wiki-using-the-terminal/#respond Sat, 20 Jul 2013 07:18:50 +0000 https://www.derekdemuro.com/?p=3451 How to transfer files over servers flawlessly.

If you followed the previous tutorial, you’d know how to transfer files over servers without passwords.

So to transfer a file from server to server issue the following command (USING SCP).

scp /path/to/my.file me@otherserver(link sends e-mail):/path/to/destination/my.file

Now the same using Rsync:

# apt-get install rsync

Or

# apt-get install rsync

Commands:

  • –delete : delete files that don’t exist on sender (system)
  • -v : Verbose (try -vv for more detailed information)
  • -e “ssh options” : specify the ssh as remote shell
  • -a : archive mode
  • -r : recurse into directories
  • -z : compress file data

Now copy to remote server:

Copy file from /www/backup.tar.gz to a remote server called new.in

$ rsync -v -e ssh /www/backup.tar.gz user@new.in(link sends e-mail):~

Output:

Password:
sent 19099 bytes  received 36 bytes  1093.43 bytes/sec
total size is 19014  speedup is 0.99

Copy file /home/user/webroot.txt from a remote server new.in to a local computer’s /tmp directory:

rsync -v -e ssh user@new.in (link sends e-mail):~/webroot.txt /tmp

Synchronize a local directory with a remote directory

rsync -r -a -v -e "ssh -l user" --delete /local/webroot new.in:/webroot

Synchronize a remote directory with a local directory

rsync -r -a -v -e "ssh -l user" --delete new.in:/webroot/ /local/webroot

Synchronize a local directory with a remote rsync server or vise-versa

rsync -r -a -v --delete rsync://new.in/cvs /home/cvs

Mirror a directory between my “old” and “new” web server/ftp

rsync -zavrR --delete --links --rsh="ssh -l user" my.old.server.com:/home/lighttpd /home/lighttpd

That pretty much summarizes everything you’ll need to do with files locally and remotely.

]]>
https://www.derekdemuro.com/2013/07/20/rsync-and-scp-file-transfer-wiki-using-the-terminal/feed/ 0 3451