Soylent!

April 8, 2015

My good friend Eric gave me some Soylent to try today.

image

Soylent Meal Replacement

The taste is fairly bland, but not unpleasant. I had it instead of lunch today and it genuinely filled me up. I would definitely try it again.

Simple rsync Helper Script

If you have multiple servers that you send files over rsync to regularly then this simple little rsync script might be helpful to you.

I love using rsync, but mostly I use the same options and only a few destinations. To send a file to my homelab server, I would have to type:

rsync -avzP -e "ssh -p 1234" /location/of/source/file.txt user@notmyrealdoamin.com:/location/of/destination/file.txt

True, it’s not that much to remember, but I wanted a faster way to do it. I also wanted to specify a default “Uploads” folder so that I could just send the file and figure out where to put it later. With my script alias’d to ‘rs’ in by .bashrc, all I have to type now is:

rs /location/of/source/file.txt servernickname /destination/file.txt

And if I don’t feel like specifying a location, I can just do:

rs file.txt servernickname

This will send the file to the ~/Uploads folder on the specified server.

The script is pasted below. Just save it somewhere convenient for you. I keep mine in ~/Scripts.

#!/bin/bash

#######################################
#
# A simple rsync helper script to send files to one of several predefined servers.
# rsync is set to use -avzP, if you want different options enter them below
# Check man rsync for a full list of options
# use: rs.sh sourcefile servername destination
# if no destination is specififed, the file will be placed in the ~/Uploads folder on the server
#
# Credit: jay-baker.com
#######################################

#########################################
#
# Defines the sourcefile variable as the first term entered after the script is called,
# and the servername variable as the second term entered after the script is called.
#
#########################################

sourcefile="$1"
servername="$2"

##########################################
#
# This will convert the source file to just its file name, stripping away the directories, but leaving the extension.
# This is useful if we don't feel like specifying a destination on the server. 
#
##########################################

filename="${sourcefile##*/}"

##########################################
#
# This basically says that if we don't specify a destination on the server to use, then make the 
# default destination be the ~/Uploads folder, preserving the orginal filename.
# If you want to specify a different default folder, then change the "destination=~/Uploads/$filename"  
# line to "destination=/$filename".
#
##########################################

if [ "$#" = "2" ]; then
	destination=~/Uploads/$filename
 else
	destination="$3"
fi

##########################################
#
# If you have multiple servers to upload to then this is where you would enter them.
# Just enterer your own server information below. Check out
# the example below for guidance. You can give each of your servers a simple nickname.
# Be sure to specifiy which port your server listens on for ssh. You didn't leave it set to
# port 22 did you? ;) Note that you can also change which options rsync uses here. 
# You could set different options for each server.
#
# Example Server
# if [ "$servername" = "" ]; then
# 	  echo -e "Sending $filename to $servername ... PewPew!"
#	  rsync -avzP -e "ssh -p " $sourcefile @:$destination
# fi
#
##########################################

#Server1
if [ "$servername" = "server1"  ]; then
	 echo -e "Sending $filename to $servername ... PewPew!"
	 rsync -avzP -e "ssh -p 2222" $sourcefile user@server1.com:$destination
fi

#Server 2
if [ "$servername" = "server2" ]; then
	 echo -e "Sending $filename to $servername ... PewPew!"
	 rsync -avzP -e "ssh -p 2222" $sourcefile user@server2.org:$destination
fi

#Server 3
if [ "$servername" = "server3" ]; then
	 echo -e "Sending $filename to $servername ... PewPew!"
	 rsync -avzP -e "ssh -p 3333" $sourcefile user@server3.server.com:$destination
	
fi

exit 0

Don’t forget to make it executable with:

sudo chmod +x rs.sh

And if you want to add an alias for it, just open up your ~/.bashrc in your text editor of choice and add the following line:

alias rs='/home/user/Scripts/rs.sh'

Replace user with your username and the rest with where you saved your script to.

This was a fun little project I did last night. I think I’ll add a little progress bar to it next.

I Passed!

April 7, 2015

I just passed my Linux Essentials Certification exam! The Linux Academy course certainly helped, but a lot of the questions are things you’ll be forced to learn just trying to install Arch.

Hopefully my Linux hobby will be turning into my Linux career soon!

LPI Linux Essentials

LPI Linux Essentials

Linux Essentials Certification

April 5, 2015

I just finished up the Linux Essentials Certification training course over at linuxacademy.com. I definitely learned some new things, but it was mostly review for me at this point ;) I’m really enjoying Linux Academy so far. They even give you a little certificate pdf to print out:

linuxessentials

I take the actual certification test this Tuesday. Now I’m on to the Linux+ LPIC Level 1 cert.

SSH Permission Problems

April 3, 2015

If you’re having trouble getting SSH keys to work, then permissions may be to blame.

SSH will check permissions for the .ssh/authorized_keys files, the .ssh folder, as well as your /home/user folder before allowing authentication with keys. It makes sense because if other users could modify your .ssh folder and authorized_keys file, then they could insert their own public key and gain access to your account.

If you’ve set everything else up properly to enable SSH to authenticate via keys and it still won’t work, then check the permissions on your home and .ssh folders. If you’ve mucked them up somehow, then you can appease SSH by fixing them with these commands:

On the server:

chmod g-w /home/your_user
chmod 700 /home/your_user/.ssh
chmod 600 /home/your_user/.ssh/authorized_keys