Wednesday, December 4, 2013

Access and stream a webcam over ssh to vlc

Ever had the desire to see if someone was on your computer? Wished you could get on there and just see through your webcam? Me neither, but one day I got curious and wanted to see if/how it could be done. It's kind of a beast of a command, but I just put it in a script which makes it very easy to use.

What you need:
ffmpeg
vlc (or mplayer)

Here's the script.( I actually got it from here. Then just changed it to use vlc because it seems to work better for me.


#! /bin/bash

B="100K"
F="ogg"
ssh <remote_host> ffmpeg -b $B -an -f video4linux2 \
    -s 320x240 -r 10 -i /dev/video0 -b $B -f $F - \
    | vlc -


I would break it down for you but I haven't gotten familiar enough with the ffmpeg command. So all I really do is copy and paste, and I only have a general idea of what it is doing. It worked when I copied it so I didn't need to figure it out to change it. If it isn't working, the first thing I would check is the device name in case it's not /dev/video0
vlc -
just tells vlc to read from stdin.(the pipe)

In my script I substituted <remote_host> for $1 so from the command line I can just run
$./script_name <remote_host>
since I wanted to be able to use it on different computers/webcams instead of just one (if I get more than one webcam on one computer then I may also have /dev/video0 passed as a parameter.

You can change the size with the -s flag I changed mine from 320x240 to 640x480 and it streamed fine.

It may take a few seconds for the picture to actually come through and be received, (I know it does for me) so once you run it then give it a little minute to get that data through to vlc.

So there it is. Just for fun.

Wednesday, November 27, 2013

Useful networking commands

I started to begin a post about useful linux commands and command line tricks. It didn't take long for me to realize that would make a very very long post.

I'm going to start with some more common commands and some I've looked at recently. I expect this list to grow. For most of this I will list the command, my most common use(s) for it, and maybe some examples.

netstat
Useful for seeing what ports are open on your computer and what process is manning those ports. I might use this to make sure something like and ssh-server is running. Very useful on servers - dns,mail,web - for making sure your programs are configures to use the right ports.
netstat -natp
sudo netstat -natp|grep 'sshd'

ssh
If you don't know what this is for or how to use it, I don't see how anything else in this post will help you much.

traceroute
Traces the route a packet takes to get to a destination. I haven't found a really great regular/common use for it, but it is fun to run every once to a while to see where things are going, and what route they are taking.
traceroute www.google.com

mtr
It does the same as traceroute but it consistently pings each hop, and keeps track of packets - dropped, etc - can be useful for seeing where a connection may be getting hung up.
mtr www.google.com

xtightvncviewer
I use this all the time on my personal computers. I have one laptop that the battery doesn't work in, so it's always connected to the tv. It's nice to be able to connect to it from any other computer to change stuff. Or if I am trying to follow something my wife is doing on the computer and guide her through it I can connect in view only mode to always have a visual.
vncviewer remote.ip.addr[:port]
vncviewer -viewonly remote.ip.addr[:port]

whois
This can be useful, but like traceroute is mostly a curiosity thing. It will tell you who a particular ip address is registered to in the whois database.
whois ip.addr

nmap
This is a powerful great program that has many many uses. My most command is seeing things like what other computers are on the network and what services they are running. It scans the network and displays information.
nmap -v -sT -rF 192.168.0.0/24
The above command runs an nmap scan in verbose mode (-v -sT), scans the ip addresses between 192.168.0.0-255 (192.168.0.0/24), Scans in fast mode the most common ports (-F) and scans ports consecutively - not randomly (-r).
I use this with grep to show only the info on open ports.
If all I want to see is the open ssh ports on my network I can use -p22 instead of -rF

sshuttle
This is one great program. I had never heard of it until recently, but it's pretty much the bomb. It can do more but the first thing I've used it fore was to set connect to another computer (via ssh) and route all network traffic through the tunnel. (pretty much sets up a VPN for you via ssh). You can use it to get around dns blocks. Or if someone wants to join your LAN game who is not on your LAN sshuttle will put you on their network.
sshuttle -r <server> --dns 0/0
I did run into a little bit of trouble on ubuntu 12.04 my first time trying it and I actually had to run these comands on the client and server (both ubuntu 12.04)
sudo dpkg-reconfigure resolvconf (select yes on any prompts)
sudo resolvconf --enable-updates
sudo reboot

sshfs
mount an ssh filesystem, I already have this one in another post but here it is for redundancy. You can mount a folder from one computer to an empty folder on your computer. syntax is similar to scp
sshfs <server>:/path/to/source /path/to/destination

Well that's it for now, I'm sure the list will grow.

Monday, September 16, 2013

Using a Raspberry Pi as a media server

Just got a Raspberry Pi. Pretty sweet. So far I like it.

I've had this post as a draft for quite a while, planning to make some great interesting post, but I've run into quite a bit of trouble trying to find a reliable setup that I liked, and that worked.

Here's what I've got that works ok so far:

First off. I don't have that big of an sd card(which is like the hard drive) for my pi. and all of my music is on my desktop computer. First thing I do is use sshfs to gain access to my music.
$sshfs desktop:Music/ Music/
I use public/private rsa keys to connect so I don't need a password. I also have the desktop computer's ip defined in my /etc/hosts file. For any help check here.

Now that I have access to my music, my most used tool is cmus. It is a music player that supports a music library, has vi like commands, and runs inside a terminal. There are others out there, the first I tried was MOC, but after trying cmus I switched.

After logging into my pi via ssh. I run tmux.(more info about tmux here.), then run cmus, find the music I want to listen to, start playing, then detach tmux, and I can then exit ssh.

Another option. If you wanted to control your music from say... your phone. Then I would use:
$vlc -I http ~/Music/
This will run vlc as an http service, the the Music/ folder as the main library. I was using this but I have a large music library, and it was hard to navigate very well. If you specified the folder with all the music you would like to listen to I think this would probably work better.

Currently working on running the nuvola music player, then using nuvolaplayer-client to control it from another computer. If I get it working I will definitely update.
=================
UPDATE: I just installed OpenELEC on my raspberry pi (It runs xbmc). It's easy to set up. I would recommend this method if you are going to be using it for different types of media.

Shell history search

Found at http://lifehacker.com/supercharge-your-command-lines-history-search-with-fou-478683529
I have found this to be very useful. 
create file ~/.inputrc and add these lines:

"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

This will make it so that when you use the up arrow to go through your search history, if you have anything already typed, it will only search anything with that term. e.g. if you want to run a sudo command from before you can type sudo, then use the up arrow to search commands that were run with sudo.

Monday, September 2, 2013

Using your ssh config file to connect to a computer through a gateway.

At my school I have some public IP addresses and virtual machines for them to use for class projects. I enjoy connecting from home but I have to go through the school's ssh server to connect to a vm(virtual maching). Having to hop through the school's server every single time I want to connect can be cumbersome, and also makes it more difficult to send files to my vm, since I have to send the file to the ssh server, then connect to it and send it again to the vm.
The other day I started looking for a way to modify my ~/.ssh/config file to have it automatically go to the vm. I tried a few different things. Some didn't work and some weren't working because of a  mistake of my own. Finally I found how to make it work. My config file is set up like so:
Host school
HostName domain.name.of.school.ssh.server
User my_school_username

Host ns1
HostName <ip of my master nameserver>
ProxyCommand ssh school -W %h:%p

Host ns2
HostName <ip of slave nameserver>
ProxyCommand ssh school -W %h:%p

The computers ns1 and ns2 are the ones that are behind the school's ssh server, and school I set as the ssh server. the ProxyCommand lines let ssh know that every time I want to connect to ns1 or ns2 that I need to go through 'school'.
One problem I ran into was that I tried to use the HostName ns1 or ns2(since they are designated as such in the ssh config on the school server). That doesn't work. You have to put in the ip of the machine.

Enabling the right click on an hp pavilion dm4 with ubuntu 12.04

I have a 14" HP Pavilion dm4 laptop and like most of my laptops, the mousepad always seems to have some type of problem at the beginning. On the dm4 my problem was that the right click didn't work. after finding an askubuntu.com question about it I found that I needed to run these three commands.
synclient RightButtonAreaRight=1
synclient RightButtonAreaBottom=1
synclient AreaBottomEdge=3500
Sadly, I can not expound really on what the synclient command does, I just know that I needed to run all three before it would work and I have to run them each time I reboot (I'll try and figure out how have it stick even after rebooting and edit this post when I do.)

Send a message to another computer via ssh

I don't know if everyone else has the same problem as me, but I have two computers in different rooms, and sometimes my wife and I are on each computer. Sometimes I want to tell my wife something or send her a message, but I'm just too lazy to get up and go into the other room to talk to her. One thing I do have is ssh access to all of my computers. After searching a little (there's references to this just about everywhere), I found how to send a message to my wife via ssh.
ssh
export DISPLAY=:0
notify-send "Message"
Now I had a computer before that for some reason or another, the default monitor/display wasn't 0 and it took some searching to find out which was the right one. Although the easiest way would probably be to increment the display number until you find the right one.
notify-send will send a notification to the screen which will time out and can easily be missed if the person on the other computer is not watching. You can also put a message in a text file, then open it up with something like gvim textfile.txt which will open a new window with the text file (gvim can also be replaced with the more common gedit)
Once you export the display in fact, you can open up any graphical program, and it will open up on that computer.
If you open up a program and then want to close after, you can run
killall <program_name>
to close it.

Sunday, August 25, 2013

Using sshfs to set up a filesystem via ssh

I stumbled upon this because I wanted to use my Raspberry Pi as a media device. (There'll be a great post on some ways to do that but I haven't figured out how I want to do it and gotten it to work yet.) Basically, my raspberry pi doesn't have enough room for all of my media. (mainly just music is all I was working with) and all of my music is on another computer on the network. I tried setting up an ftp server on that computer, which will work, I just didn't like it very much. Eventually I found sshfs which was great for what I wanted to do.

To install sshfs if you don't already have it. - on ubuntu/similar.
sudo apt-get install sshfs

If you have used ssh or scp then sshfs should be pretty simple It's set up like this:
sshfs [user@]host:[dir] mountpoint [options]

So, lets say I'm logged into my raspberry pi, and I want, let's say to be able to access all of my music from my desktop computer through a folder in my home directory(on my raspberry pi). My desktop is named sigsauer.

From my raspberry pi:
mkdir ~/Music/
(if it doesn't already exist)
then,
sshfs sigsauer:Music/ ~/Music/
One thing I learned at this point, is that when you install new system you need to remember to keep you /etc/hosts file up-to-date. Because if you don't you might run into problems when trying to use the computer name. Once I got past that little hangup, then things started to work perfectly.
Now I could go into my Music folder which I just created and access all of the files as if they were local.
This has been great for me since I have 2 computers and a raspberry pi, that stay at home and are always on the same network, I don't like having my music library all over the place, adding music here and there then making a mess when I try to compile it. Now I have everything reading off and editing the same library, making it much easier to keep my library organized.
One of the computers has ubuntu server on it and I didn't feel like dealing with installing dropbox on it, so I simply added a command to my crontab to mount the dropbox folder from my desktop computer to my server computer. More about crontab here.
Keep in mind that to add it to the crontab, since it can't ask you for a password you need to have passwordless ssh authentication. I have a little bit of instruction about how to do that which I may have to turn into a new post, but I found the easiest way for me is to simply copy the whole ~/.ssh/ folder from one computer to the other, then delete any offending keys from ~/.ssh/known_hosts file.

Once you are done with sshfs and don't need access to the files anymore, you can unmount the directory by simply:
fusermount -u <mount_point>
so to unmount my Music -
fusermount -u ~/Music/

And now if you went into the folder it should be empty.

Wednesday, July 10, 2013

Adding cronjobs using crontab in Ubuntu 12.04/Mint 13

Cronjobs are a good way to run a script every so often (hour, day, week, at reboot, etc.) Some things I use it for are:
To keep my public ip address updated and saved in my Dropbox folder,
To mount my external hard drive on my ubuntu server every time it reboots,
And to update my psmouse-alps driver which needs to be updated at reboot as well.

I'm sure someone else can find many other possible more useful applications for this.

First think you need to do is find out what privileges you need to do what you want to do. Since all i need to update my public ip is access to the internet and also my dropbox folder, I only needed my regular user privileges.

Crontab has some pretty good explanations and even gives you an example in the comment in the file. The first 5 fields (separated by spaces) are to tell it when/how often you want to run a certain command/script. Right after the first five fields you just put the command/script you want to run.
The example used in the file:

0 5 * * 1 tar -zcf /var/backups/home.tgz /home/

I found some pretty good examples to help you to understand the schedule notation that crontab uses. Wikipedia has a useful article here. Also this site was very useful. What I found was also very useful was some of the shortcuts, listed here.
They are:
@reboot
@yearly
@annually
@monthly
@weekly
@daily
@midnight
@hourly 

So on my ubuntu server, since I need root privileges to mount my external drive, I edit the crontab by executing:
sudo crontab -e
Then I choose to edit it with vim since it is my preferred text editor, and add this line to have my external hard drive mount at boot:
@reboot mount -t ntfs-3g /dev/sdb1 /media/external
And to have my ip update every day I run:
crontab -e
(as a regular user, I don't need root for this)
and have it run my script to update the ip daily:
@daily /home/user/bin/ip_script
For any interested my script is very simple(3 lines), and only needs the curl utility installed.
sudo apt-get install curl
also dropbox if you don't already have it.
then open a text editor and write

#! /bin/bash
curl ifconfig.me >> public_ip
mv public_ip ~/Dropbox/

Then name and save the file, make it executable and add it to crontab.

Setting up opendns.com with Ubuntu 12.04/Mint 13

opendns.com is a great service for blocking and/or tracking web access. Although most people probably have a dynamic ip address, and it can be difficult to find a good way to keep your ip up to date with their site and servers. This is the way I found the easiest for me.

Go to www.opendns.com click on 'Sign In' in the top right corner. Then click on the Get Started! link and set up an account. I would suggest either of the free accounts. The only difference is that the FamilyShield account is preconfigured. I ended up configuring it myself anyway.

Then log in. Go to the Settings tab. Your own ip should be at the very top of the page(above the nav bar). You can use that to add your network. Once you have added your network you can click on your network/ip and set up your filtering preferences.
allowed on this network.
Now the way I chose to set my network up to go through the opendns servers was by configuring the ip addresses of the opendns servers on my router. This can be different depending on your router, mine was very simple. There was a place to specify static dns servers. I just entered the ip's (they can be found on the opendns website at the bottom of the page.) saved the configuration and all my web traffic was now going through the opendns servers.

Once you get to this point, if you try to visit a blocked site it should come up with an opendns site telling you the domain is blocked. If you have a static ip, then at this point you are done. Most of us I would imagine have a dynamic ip and need to set something up so that this will stay updated. I used DNS-O-Matic provided by same people who made opendns

Go to DNS-O-Matic website: http://www.dnsomatic.com/
Since it is an opendns service you don't need to create an account, you can use the one you just created with opendns.
Click on Sign In, use your opendsn username & password.
Click on the 'Add a service' button and select OpenDNS from the drop down list.
It will add the opendns service and then the status will be waiting for confirmation or something similar.

Now is the fun part. I found my preferred method to keep this up to date was by using ddclient. In a terminal type:
sudo apt-get install ddclient
It will then ask you a bunch of questions. I tried to match this as close as possible although, the questions and names for things are slightly different so it doesn't matter too much what you put in there since we will go to the config file and change it anyways.
After it is installed open up with sudo/root priviledges /etc/ddclient.conf in your favorite text editor. For me:
sudo vim /etc/ddclient.conf

and make it look like this.
The only unique change you need are your username and password, everything else you want to match the file in the previous link. Save the file and run: sudo ddclient

Now you can run ddclient every time your ip changes and it will keep everything updated or you can add it as a cron job, I would say once a day would be enough for most any isp. See how here.

Tuesday, July 9, 2013

Regular things I do after a fresh install. (Ubuntu 12.04/Mint 13)

Here's some things I like to do after a fresh install of ubuntu/mint.

Install apt-fast:

sudo add-apt-repository ppa:apt-fast/stable
sudo apt-get update; sudo apt-get install apt-fast

Then update(I always use apt-fast since I know there will be a lot to download):
sudo apt-fast update; sudo apt-fast upgrade

Install vim from apt(if not already installed)

Edit my /etc/hosts file to include all of the computers on my home network. Copy over files that I backed up on those computers.

Disable apport(if ubuntu. if mint then disable after installing software-center):
sudo vim /etc/default/apport   --- change '1' to '0' and save.
sudo service apport stop

Install chromium-browser use apt
Install chrome from .deb file
Install google-earth from .deb
Install google music manager from .deb
Install google talk plugin from .deb
Install teamviewer from .deb
Install VMware Player from .bundle (rename from .txt when saving(yes you can just still execute it regardless... just change it... because.))
Install synapse from apt
Install fogger:

sudo add-apt-repository ppa:loneowais/fogger
(update; and install fogger)

Install gimp if not at least 2.8(because I like the single window mode)

sudo add-apt-repository ppa:otto-kesselgulash/gimp
(update; and install gimp)

Install dropbox from apt
run/setup dropbox

Tmux basics

Using tmux. What is tmux? How does it work and what's it useful for? Someone once recommended tmux as something useful to use. So I started looking into it without really knowing what it was. Here I'll tell you how it's actually useful to me. So, what is it? Here's what they have to say about it on sourceforge. "tmux is a terminal multiplexer. What is a terminal multiplexer? It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more. See the manual."

Well that didn't make much sense to me and it took a bit of searching around and reading manuals and the like to find out how tmux would actually be useful to me. 
For me tmux is pretty much just a way to run multiple terminals inside of one. Here's mine with 3 terminals open:

It just looks like one of course(you can only type into one at a time). If you look at the green bar at the bottom you can see the names of each: 0:bash, 1:bash~, 2:bash*
So far this hasn't impressed me. I mean, that's just like having different tabs right? I can even do that with the terminal so that's not useful unless maybe I was on a server install. -- True. Where tmux really becomes useful is with it's ability to detach and attach sessions. I have 3-4 different computers(one isn't on too much) and I'm too lazy to get up and go to each computer when I find something cool that I want to install on all my computers, or when they all need to be updated. A lot of the time when I am at home it's not a problem to simply leave a terminal open connected to one of the computers via ssh while it installs something/updates/while running a script. Although if I decide I do want to get off my lazy but and go to one of the other computers(for instance from my laptop to my desktop) then I have to make sure the laptop stays up and running, or I have to kill the command and rerun it on the computer when I get there. If I am using tmux however I can simply detach the session, and reattach it when I get to the other computer. 
Where I find I get the most use out of tmux is when I am connecting to a school server, or when I am connecting on my laptop from somewhere other than home. When connecting from somewhere other than home(and especially if I am installing something/running a script that will take a while I can't be sure that my in-laws internet will stay connected the whole time(if you look a the box(modem) wrong it disconnects). With tmux I can start apt-get then detach and it will be running in the background the whole time... and I don't need to be connected to that computer via ssh.
So now that I've bored you all with the usefulness of tmux for me, here's a few simple commands that I use that can hopefully get you started. If you start to find it useful and want to use it more I recommend going to one of the other sites out there to see more things you can do with it.
To start tmux simply type the command:
    tmux
To open a new terminal instance:
    Ctrl+b c
To close a terminal:
    Ctrl+b x
To go to the next terminal:
    Ctrl+b n
To detach the session:
    Ctrl+b d
To reattach after detaching use command:
    tmux attach

UPDATE: Wow I just realized this post is pretty long. For a crash course just install tmux and play with the above commands in the last paragraph. After learning and using tmux a bit more I'd say its time to add some more commands.

I simply looked at the man pages and created a cheat sheet of just the commands here.

Some of the main ones I'm using aside from the above are:
To split terminal  vertically:
   Ctrl+b %
To split horizontally:
   Ctrl+b "
To navigate through existing panes:
   Ctrl+b LEFT,RIGHT,UP,DOWN
Holding Ctrl+b down while using the navigation buttons will resize your current pane.

Saturday, June 29, 2013

Encryption using openssl

Inspired from a school assignment from http://cit.dixie.edu/it/2400/labs/security_lab.php
using openssl to encrypt a file. Don't know that this post really needs to be written since I found a very good howto at http://osxdaily.com/2012/01/30/encrypt-and-decrypt-files-with-openssl/ but I might as well give people another one.

openssl can be used on the command line to encrypt/decrypt different files. The command structure is something like this:

openssl [type of encryption to use] -in [input filename] -out [output filename]

Then if you would like to decrypt a file you just add the -d flag

openssl [type of encryption to use] -d -in [input filename] -out [output filename]

and then of course the input file would be the encrypted file, which would then output the plaintext (after you provide the correct passphrase/key)

I got curious about trying to make a tar.gz/bz2 file out of various files you would like to encrypt. I haven't tryed this on very large files, but I have read somewhere that it is not recommended and may not work. Although for throwing a few documents together, mainly text or maybe a few pics, it works fine. I actually learned a whole lot about shell scripting with this project. Here is the code:
########################
#! /bin/bash
USAGE=$'Usage: ./encrypt <output_filename> <file1> <file2> <...>\n-h\tshow help\n-o\toverwrite file\n-d\tdecrypt\n-v\tshow version'
FLAGS=()
FILES=()
FILENAME=()
if [ "$#" -lt 2 ]
then
echo "$USAGE"
exit 1
fi
for p in "$@"
do
if [ -f "$p" ]
then
FILES=( "${FILES[@]}" "$p" )
elif [ -d "$p" ]
then
FILES=( "${FILES[@]}" "$p" )
elif [ "${p:0:1}" == "-" ]
then
FLAGS=( "${FLAGS[@]}" "$p" )
else
FILENAME=( "${FILENAME[@]}" "$p" )
fi
done
len=${#FILENAME[*]}
if [ "$len" -gt 1 ]
then
echo "${FILENAME[@]}"
echo "Command not recognized: ${FILENAME[0]}"
echo "$USAGE"
exit 1
fi
OVERWRITE=0
DECRYPT=0
if [ ${#FLAGS[*]} -gt 0 ]
then
for flag in "$FLAGS"
do
if [ $flag == "-o" ]
then
OVERWRITE=1
elif [ $flag == "-d" ]
then
DECRYPT=1
elif [ "$flag" == "-h" ] || [ "$flag" == "--help" ]
then
echo "$USAGE"
exit 1
elif [ "$flag" == "-v" ]
then
echo "encrypt v1.0"
exit 1
else
echo "Flag not recognized: $flag"
echo "$USAGE"
exit 1
fi
done
fi
if [ $DECRYPT -eq 0 ]
then
tar cvjf ${FILENAME[0]}.tar.bz2 ${FILES[@]}
openssl enc -aes-256-cbc -salt -in ${FILENAME[0]}.tar.bz2 -out ${FILENAME[0]}
if [ $OVERWRITE -gt 0 ]
then
rm ${FILES[@]}
fi
rm ${FILENAME[0]}.tar.bz2
exit 1
fi
openssl enc -d -aes-256-cbc -in ${FILES[0]} -out ${FILENAME[0]}.tar.bz2
tar xvjf ${FILENAME[0]}.tar.bz2
rm ${FILENAME[0]}.tar.bz2
if [ $OVERWRITE -gt 0 ]
then
rm ${FILES[0]}
fi
#############################

This can also be used to decrypt the file. I used aes-256 encryption because it seemed to be one of the most secure. Most of the code is probably for processing the command line flags, the actual code to create a tar.bz2 and encrypt it is pretty simple. This is probably about as far as I got in working with openssl. I am fascinated by cryptography and encryption, but don't really have much use for it(yet).

Controlling VLC remotely. (using vlc on ubuntu 12.10 and remote for vlc on android, or a web browser)

This is simply another resource for anyone wanting to remote control vlc on their computer. Some of the info I got from here. And some from various other blogs/articles about the same thing. First things first.. you need to have vlc installed. Use "sudo apt-get install vlc" to install it if you don't have it already. While most of the sites I've seen have shown you how to enable vlc's web interface from the gui program, for using this as more of something like a daemon/service, I personally have found it much more useful to just have it run in the background since when you close the gui it stops the service as well. Press Alt-F2 to open up the run dialog and simply type:

vlc -I http

which just starts the vlc web (or http) interface. At this point you can access this interface by opening a browser and typing "localhost:8080" in the location entry.


 You can control and use vlc from here. Although this isn't particularly useful at this point since I can do everything this interface does and more by just opening up the vlc gui. To be able to control vlc remotely, you're going to need to edit a few lines of a file. It is most likely located here: /usr/share/vlc/lua/http/.hosts
Now, using vim(or another preffered text editor), and as root(or with sudo privileges) open the file:

vim /usr/share/vlc/lua/http/.hosts

There should be a private addresses section that is all commented out. If your network is like mine and the ip addresses of all your computers are 192.168.x.x, then uncomment the line with 192.168.0.0/16. If the ip addresses on your network don't look like mine then find the line that looks like your ip and uncomment the corresponding line. Also, another option is that if you know the ip(s) of the device(s) you will be using to control vlc you can simply add it/them to the file(right after the private addresses section is fine).
The reason for all of this is that by default vlc's web interface is only accessible from localhost, or the same computer you're running it on. (which isn't very useful)

Once you have this set up you should be able to connect and control it from another device. If you are trying to access it from another computer just open up a web browser and type in http://192.168.x.x:8080 (replacing the ip address with the address of the computer you have the vlc server running on). You should get the same interface as earlier.
Controlling it from another computer can be useful, but I find it even more useful to be able to control vlc from my android smartphone. I used Remote for VLC by Peter Baldwin. Available in the play store(free). There are various others and I tried most of them, but this one seemed to be the most stable and I liked the setup the best. To connect to your computer with your phone, start the Remote for VLC app. If it doesn't automatically give you the option to add a server then go to the settings:



Click on 'Add VLC server' then enter the ip address of your computer, then type 8080 into the port(unless you specified a different port). It will connect and you can then search your music library via the 'Library' tab (it is more of a file explorer). Find the song or folder you would like to play



After selecting Play or clicking on the mp3 go to the 'Playing' tab. There you can use the media controls. For some reason the playlist just shows about all of your music, and you can't really just clear it when you want to play something else which is for me the only real downside of this app.(but I still chose it because it worked the best for me for what I wanted to do)

Wednesday, May 1, 2013

Moving the window buttons from the right side to the left in Ubuntu Gnome 12.10

Mostly posting this just as a reminder to me for when I forget how to do it again. Credit goes to 'jokerdino' from this link.

The command he gave is actually to move the buttons from the left to the right so it needs to be reversed for the opposite (which is what I'm trying to do). He gave this command for those using Unity:

gsettings set org.gnome.desktop.wm.preferences button-layout ":minimize,maximize,close"

And this one for those using Ubuntu Gnome/the Gnome-Shell(like me)

gsettings set org.gnome.shell.overrides button-layout ":minimize,maximize,close"

I simply took the second command and reversed it to my liking:

gsettings set org.gnome.shell.overrides button-layout "close,minimize,maximize:menu"

Saturday, April 27, 2013

Installing the psmouse alps driver in ubuntu 12.10

I recently upgraded to ubuntu 13.04. Couldn't get enough things to work the way I wanted, and the way they used to be, and so subsequently backed up my home folder and reinstalled 12.10. Since I had to reinstall the psmouse-alps driver for my mouspad to work with a scroll I decided to blog about it.

I searched and the best answer I found was in this link. The answer I used I believe was the third one down. It was the one with the install.sh script in it.

First off, you need to have the right kernel stuff installed.(Yeah I know, really technical). Look in your /usr/src folder and see what kernel you are using. e.g. before I install the driver mine showed

linux-headers-3.5.0-17

if this is all that shows up(and it probably will be) you will need to install your specific kernel's generic package.. I ran

sudo apt-get install linux-headers-3.5.0-17-generic

To install it you will also need to have dkms installed you can simply:

sudo apt-get install dkms

Once all that is installed, download the alps driver. Here is the link(hopefully it doesn't change).
https://docs.google.com/open?id=0BzNsvDx_ae6bQnFLQkNFT0dWc3c
Uploaded it to my drive account too just in case.
https://docs.google.com/file/d/0BwdxaDKyG0KSWmpEaTZqUU9zMkk/edit?usp=sharing

Once downloaded, navigate to the directory in which you downloaded it. then:

sudo cp psmouse-alps-dst-0.4.tar /usr/src
cd /usr/src
sudo tar xvf psmouse-alps-dst-0.4.tar

after extracting the go into the source directory:

cd psmouse-alps-dst-0.4

The instructions the person on askubuntu gave was to simply run

sudo sh install.sh

for some reason this didn't work for me when I tried it and it required a few extra things to do after. I also need to run these commands each time I start the computer so I put it in a script. Open up your text editor of choice (vim) and write these lines:

 #! /bin/bash
dkms add psmouse/alps-dst-0.4
dkms autoinstall
rmmod psmouse
modprobe psmouse

save the file, then make the file executable:

chmod 755 name_of_script

and run it:

sudo ./name_of_script

After that I simply went to System Settings->Mouse and Touchpad and then changed the settings as desired in the Mousepad tab (which wasn't there before).
Voila! And magically I could now enable multi-touch and scrolling with the mousepad.

Sunday, April 21, 2013

Mounting USB in Ubuntu Server

So I put Plex Media Server on my laptop that I installed Ubuntu Server on for the purpose of only running Plex Media Server (the monitor broke). The only problem with hosting the media server is my laptop hard drive isn't big enough to hold my media library. It does however fit on an external USB drive (for now, though I might need a bigger one in not too long). So I decided to see if I could run it with the media library on the external drive. The only problem was mounting the drive. I realized I had no clue how to do that from the command line really. So I searched for a way to do this. The answer wasn't very difficult and was explained well on the ubuntu wiki here. just two commands:

sudo mkdir /media/external

To create a mount location and, since the drive was formatted with ntfs:

sudo mount -t ntfs-3g /dev/sdb1 /media/external

to mount the drive. To find out which device it is (in case it isn't sdb1) you can run

sudo fdisk -l

to find which one it is.
I tried pmount and various other tools but this one seemed to be the only one that really worked well and did what I wanted it to. I believe with it being ntfs it will give the user permission to the drive. Whereas if it was some type of fat system you would need to finish it off with the -o flag and some arguments.

And to unmount the drive (which I never really do since it is my library) you simply:

sudo umount /media/external

Saturday, April 20, 2013

Listing sizes of stuff

Got to wondering how to show how big a file is, including all the files and folders inside of it. When one uses:

ls -l

to list files it will list every folder as size 4096 (or 4.0K if use use the -h flag as well). Well I'm pretty sure that I have more than 4KB of Music so I got looking for a way to show how big the file is. It was pretty easy to find. simply

du -hs /path/to/directory

the s flag is for summary, that way when you use the command it doesn't show the size of everything recursively, just the total.

Along with this stuff I was trying to see how to list the size of the whole drive and other partitions. One method was to use

sudo fdisk -l

but that only listed one partition for me, and didn't change the size to human readable form a much better command I found was df with the -h flag for human readable form thus

df -h

will list all partitions and their sizes, not just the one.

Wednesday, April 17, 2013

Playing a blu ray disk with Ubuntu 12.04/12.10/Mint 13

Found myself with a slight problem trying to play a blu ray disk on my laptop. crunched down, here is what I had to do to get it to work. Added a vlc repository, I'm not sure if this was necessary or if the following commands would have been sufficient but it's what I did.

sudo add-apt-repository ppa:n-muench/vlc
sudo apt-get update && sudo apt-get install vlc

I then had to install the correct codecs for blu ray

sudo apt-get install libaacs0 libbluray-bdj libbluray1

I then needed to create an aacs file and download a certificate/key.

mkdir -p ~/.config/aacs/
cd ~/.config/aacs/ && wget http://vlc-bluray.whoknowsmy.name/files/KEYDB.cfg

After that I simply opened up vlc (my prefered media player, especially for movies) went to Media>Open Disc...

Then I selected BluRay under Disc Selection, then in the dropdown menu I selected the correct device. I also read that it is important make sure the 'No disc menus' box is checked. Then hit play and enjoy the show!

Using avconv (previously ffmpeg) to record the desktop

So I was trying to figure out how to record a video of the screen. I didn't have much use for recording the microphone though. All the instructions I could find would always describe how to record a video using the microphone for audio. Here's that command for that just in case that's what you are wanting:

avconv -f alsa -i hw:0,0 -f x11grab -s 1600x900 -r 25 -i :0.0 -vcodec libx264 -acodec libmp3lame vid_file.mp4

Of course, since I didn't need microphone and I actually wanted the program's audio output, that command didn't work for me. I tried many different variations on the alsa device (hw:0,0) to no avail. Finally I found the answer somewhere was to change from using alsa to pulse, then directing to the device, eventually coming up with the command:

avconv -f pulse -i alsa_output.pci-0000_00_1b.0.analog-stereo.monitor -f x11grab -s 1600x900 -r 25 -i :2.0 -vcodec libx264 -acodec libmp3lame vid_file.mp4

The pulse device name (mine is shown as alsa_output.pci-0000_00_1b.0.analog-stereo.monitor) can by found with the command:

pactl list sources|less

Listed next to "Name:"

I'd also like to break down the command I used as best I can because nothing else I found explained much about what was going on or how the command worked and/or could be changed.
avconv is the name of the program
I believe -f is to add a new stream to the video/file so,
-f alsa/pulse
adds a new audio stream, then -i designates a device.
-f alsa -i hw:0,0 
then adds alsa device hw:0,0.

then we use -f to add a video stream(no sound) with:
-f x11grab
-s for size which on my laptop is 1600x900.
-r I believe is the framerate.
-i then adds the device/display in this instance. Almost all the examples I saw used the display :0.0, after playing with it a bit I found that on my laptop it needed to be changed and was actually :2.0

so far we have:
avconv -f alsa -i hw:0,0 -f x11grab -s 1600x900 -r 25 -i :2.0
That takes care of where we get the input.
The rest of it is the output
-vcodec libx264 tells it to use x264 as the video codec (on of the most common and is used for mp4 files)
-acodec libmp3lame tells it to use mp3 encoding for the audio
vid_file.mp4 is the filename. (The extension tells it to save in an mp4 container)

Monday, April 15, 2013

Useful IT commands

SSH
to connect to computer via ssh:
ssh username@host
to create tunnel

ssh username@host -L p1:h:p2

p1=local port (the port it is being directed to on local machine)
h=host machine, can be localhost(which will be remote machine) or machine accesible from original remote host(host)
p2=remote port, port on host machine(h) that is sending info

to be able to open up graphical applications on local computer

ssh -X username@host

to use ssh without needing a password:
first create an RSA key -

ssh-keygen

keep hitting enter for everything
will save key in ~/.ssh/
do this on both computers
then you need to send id_rsa.pub between computers. save in .ssh as authorized_keys
my preferred method (just one way, needs to be done on both)

cd ~/.ssh/
scp id_rsa.pub username@host:.
ssh username@host
cat id_rsa.pub >> ~/.ssh/authorized_keys

ARP
shows current/recent connections
arp -a

PING
sends packets (useful for checking network)
ping -c <#> <domain/ip>
-c for count without specific count will contiue until you tell it to stop

TRACEROUTE
traceroute <domain/ip>
will trace the route to specified destination and return ip's from each point along the way

WHOIS
whois <ip>
will return information about ip (like registration info)

NAT - to set up NAT on a gateway computer
sudo iptables -t nat -A POSTROUTING -o <network card:e.g. eth0> -j MASQUERADE
echo '1' | sudo tee /proc/sys/net/ipv4/ip_forward

DIG
shows dns servers, makes it possible to trace path one by one.

NMAP
nmap has various uses. my most recent = finding what other computers are on the network with me (and ip, or more specifically, just the ip)

nmap -sP 192.168.1.1-254

Worked great for me. you could also use

nmap -sP 192.168.1.1/24

These will show you the ip's that are up on your network. (well, on the 192.168.1.x network)