Tuesday, July 21, 2015

Set default browser LXDE (Fedora)

For some reason going to Menu>Preferences>Prefered Applications and choosing Google Chrome didn't work. Midori was still handling all my http/https links.
Solution for this is xdg-mime

To check default browser for http and https type in terminal

xdg-mime query default x-scheme-handler/http

xdg-mime query default x-scheme-handler/https

This command will give you output .desktop file which is used to open those links. To set them to Google Chrome, command is

xdg-mime default google-chrome.desktop x-scheme-handler/https

and for http

xdg-mime default google-chrome.desktop x-scheme-handler/https

Instead of google-chrome.desktop you can use any .desktop file to set default application.

Thursday, July 9, 2015

Fedora 22 LXDE VNC server (x11vnc)

For connecting to your machine over the Internet, Teamviewer is super-easy to use. But for one reason or another it's not always possible. Solution to this is x11vnc.

First, install x11vnc to your machine using

sudo dnf install x11vnc

You don't want anybody to be able to connect to your machine so you should setup password

x11vnc -storepasswd

This command will ask you to type in password for remoting-in to your machine and save it to ~/.vnc/passwd

Now, you should test to see if your VNC server works.

x11vnc -forever -rfbauth ~/.vnc/passwd -rfbport 5900

You should be able to connect to your machine with VNC Viewer.

You could run this command every time you start your machine, but it's not really handy. I wanted to setup my machine so that x11vnc server starts as soon as login screen shows (so even if I'm not logged it I could remote connect).

To do that, open file /etc/lxdm/LoginReady and add following line

x11vnc -display :0 -forever -bg -rfbauth /home/locodog/.vnc/passwd

Please note that here you should put whole path to your VNC password file, do not use ~/.vnc/passwd

Reboot your machine and test it out.

If you don't want to go through all this, after installing x11vnc you could just use x11vnc Gui to start your vnc server.

For VNC client, after testing many I recommend Remmina. It has everything I need, bookmarks because I don't want to type in IP address every time I want to connect to remote machine and also, scaling. It's really no fun having to scroll up-down, and left-right in order to reach every corner of remote display. Keep in mind that Remmina will disconnect (or not connect at all) if color depth on client side is not same as on server side.

This post was very helpful:
http://ubuntuforums.org/showthread.php?t=1868554

Thursday, June 25, 2015

Screenshots in Fedora LXDE

I was just about to make screenshot on my system and I noticed that there is no application for that. Best solution I found is gnome-screenshot, it's easy to use and it has a nice "flash" effect when making screenshot.

Step 1 is install gnome-screenshot

sudo dnf install gnome-screenshot -y

I don't like my screenshots mixing with other pictures I have so I created directory Screenshots

mkdir ~/Pictures/Screenshots

How to make gnome-screenshot put your shots there:

       gsettings set org.gnome.gnome-screenshot auto-save-directory "file:///home/$USER/Pictures/Screenshots/"
 

Now we need to make "shortcut" to taking a screenshot. In my case, button PrintScreen will take full screenshoot and Ctrl+PrintScreen will make only active windows screenshot.

Open ~/.config/openbox/lxde-rc.xml with your favorite editor and insert these lines inside before </keyboard> line.

<keybind key="Print">
        <action name="Execute">
                <command>gnome-screenshot</command>
        </action>
</keybind>
<keybind key="C-Print">
        <action name="Execute">
                <command>gnome-screenshot -w</command>
        </action>
</keybind>

After you saved and closed file, execute:

openbox --reconfigure

Tuesday, June 16, 2015

Mikrotik backup script using SSH/SCP - easy and dirty way

*Disclaimer*
This is not high-end, ultra safe script. It's considered a bad practice to store your passwords in cleartext, especially in script file. I am beginner in scripting and this is just a way to automate task that when done by hand could take very long time. But, if you still want to proceed, read on!

For this script to work we will need to install program called sshpass, install it from your distro repository. This script assumes that all your Mikrotik devices have same username and password and SSH service enabled.
EDIT: After some experimenting it seems that sometimes ConnectTimeout=10 is not enough, if you have troubles connecting, increase to 20.

#!/bin/bash
#Don't just copy and paste this script, adjust all paths to your needs
#You can remove any line starting with hashtag because those are comments and they are not executed

NOW=$(date +%d-%b)
#This line creates variable NOW with day and month, like "03-May"
#I will use this example, "03-May" to make it easier to follow

COUNTER=0
#sets counter to zero

mkdir /home/locodog/backups/mikrotik/$NOW
#creates directory with name according to date "03-May" for example

for i in $(cat /home/locodog/mikrotik-backup-script/tiks.txt); do
#tiks.txt is file that has list of all Mikrotik devices you want to backup
COUNTER=$((COUNTER + 1))
#adds +1 to counter for every device it attempts to backup

echo -e $COUNTER"." "Backing up device \033[1m$i\033[0m" 
#tells you which device is currently being backed up

sshpass -p "password" ssh -oStrictHostKeyChecking=no -o ConnectTimeout=15 $i -l username system backup save name=$NOW
#Connects to mikrotik device from list and creates backup file with name "03-May"

sshpass -p "password" scp -oStrictHostKeyChecking=no -o ConnectTimeout=10 username@$i:$NOW.backup /home/locodog/backups/mikrotik/$NOW/$i.backup
#Downloads previously created backup file but now that file is downloaded into folder "03-May" 
#and file has name 192.168.1.1.backup (or whatever IP address your Mikrotik has
#keep in mind that backup file inside your Mikrotik will not be deleted and it will have a name 03-May.backup
done

TOTAL=$(echo $COUNTER)
#Creates variable "total" with value equal to total number of devices that were backed up (or attempted)
for f in $(cat /home/locodog/mikrotik-backup-script/tiks.txt); do
if [ ! -f /home/locodog/backups/mikrotik/$NOW/$f.backup ];
 then
echo -e "Backup of \033[1m$f\033[0m was not done" && COUNTER=$((COUNTER - 1 ))
fi
done
#this section checks is there any backup file missing and
#gives you IP address of device where backup could not be performed for whatever reason

echo -e "Backup was successful on \033[1m$COUNTER\033[0m out of \033[1m$TOTAL\033[0m Mikrotik devices."
#Here you get report, on how many devices did you try to do backup and how many sucessful

After adjusting this script to your needs save it in file for example backup-mikrotik.sh
and make it executable with chmod +x backup-mikrotik.sh

File tiks.txt (or whatever you decide to call it) should have list of IP addresses of your Mikrotik devices like this:
192.168.1.1
192.168.1.2
192.163.25.4
10.25.66.8

And so on. This file should be plain text, that means don't create it with LibreOffice or anything like that. Use plain text editor like Gedit, Kate, Leafpad, Vim.

Wednesday, June 10, 2015

Samsung Printer/Scanner drivers for Linux Fedora

To install Samsung printer drivers go to
http://www.samsung.com/us/support/downloads
Click on Printers and choose your printer model. Most likely it will be tar.gz file. In termial go to folder where you downloaded the file. In most cases it will be ~/Downloads and type

tar xvf uld_v1.00.06.tar.gz

This is name of my downloaded file, you will here type name of file you downloaded. After content of archive is extracted type

sudo ~/Downloads/uld/install.sh

Also, you will here type path where you extracted file from step 1. This command must be executed with elevated privileges (sudo) or it will fail.
Confirm execution of script with "y" and go through EULA with Enter. Be carefull because after EULA you will have another confirmation and if you just keep pressing Enter like maniac default answer will be "No" and you will have to run script again. So, choose yes. Next you will be asked do you want to make firewall rules if you intent do use printer over network, after answering that (I choosed No) script will finish installation of drivers.
Start Printer Settings and turn on you printer. Click Add and select your make and model. You will be asked to install drivers, but since we already did that you can hit Cancel. Confirm friendly name and apply settings. Printer installation should now be completed, if you want you can print test page.

Monday, June 8, 2015

SSH Access Denied and SFTP connection closed Fedora

After having my Fedora 21 messed enough that it wasn't worth fixing, I decided to install new shiny Fedora 22 LXDE spin. Installation went (almost) good. And you will see why I say almost.

Upon finishing installation and enabling ssh server with

systemctl start sshd
systemctl enable sshd

I tried to login from my other computer. After asking for password it would simply return Access Denied. Using verbose mode didn't help me much. With my first google search I came upon this problem with guy who was asking help simply saying that he solved his problem by changing his password. 
I know my password, I just typed it in to log onto my system, and I have saved profile on second computer so I don't even need to type it. (yes, I know it's a security hole).
I never had pleasure to meet with ssh setup so I assumed that there is something in sshd_config that I didn't set correctly. So, instead of going through all settings I just copied sshd_config from co-worker's computer, because it works there.
No go. Another 20 minutes of going through every single line inside config file, no go.
Eventually i thought "hmm, maybe I should try changing the password"...
And I kid you not, it was the solution. I even typed in same exact password and this time it worked.

Now just to restore some files I previously backed up, over sftp, I'm too lazy to copy it over usb drive.
sftp username@hostname...
insert password
Connection Closed
Goddamit!

Let's browse Google some more. Most people were having trouble with key login, but almost nobody with password.

sftp -v myusername@myhost
And there it was
debug1: Exit code 127

To make story short, when I copied sshd_config file from another computer I didn't consider that it was Slackware. In most cases that wouldn't matter, but in mine it did because in sshd_config there is line

Subsystem sftp /usr/libexec/sftp-server

But on my system, location of sftp server was

/usr/libexec/openssh/sftp-server

After changing that line in config file and systemctl restart sshd it worked.

Saturday, June 6, 2015

DNS probe finished no internet problem on Windows 8

One day I fired my laptop with Windows 8.1 on it, connected to home WiFi and started Chrome but no website could be open.
Error was DNS probe finished no internet.

I was able to ping 8.8.8.8 and anything else by IP address, but no hostname could be resolved. Tried setting Google DNS servers, OpenDNS servers, but with same result.

ipconfig /flushdns also didn't do any good.

netsh winsock reset didn't help

Other device on that same WiFi network (my phone) worked just fine. After connecting laptop to cable connection everything worked without any problems. It was clear that problem was wireless related.
Next step was downloading new set of drivers for wireless card. Completely uninstalling and deleting old drivers and installing new (actually it was same version) solved my problem.

One more possible solution I came accross, but I didn't have chance to test because driver reinstallation fixed everything is

netsh int tcp set heuristics disabled
netsh int tcp set global autotuninglevel=disabled
netsh int tcp set global rss=enabled