Solutions to IT problems

Solutions I found when learning new IT stuff

Archive for October 2011

Manage MySQL running on Ubuntu Server with a GUI

leave a comment »

Introduction

In my daily work I often use databases as a tool for cleaning, reorganizing or visualizing different kind of research data. For these task a GUI gives you so much more compared to the command line tool.

The easy way

Install and configure phpMyAdmin, a web based MySQL Administration GUI. You must have a web server (eg. apache) installed to be able to use it. Depending on your usage I highly recommend to take certain security aspects into account.

Connect using a Client GUI Tool

An alternative to MySQL Workbench is HeidiSQL a small, lightweight client (Windows) for MySQL and MS SQL. Following steps will work for either product. I assume you followed my previous tutorial on how to connect to Ubuntu Server and hence be able to use your editor of choice if you do not want to do it in vi.

  1. Open /etc/mysql/my.cnf
  2. Find the line with the entry bind-address
  3. Comment that line
  4. Restart mysql: sudo service mysql restart
  5. In the terminal connect to mysql: mysql -u root -p
  6. You be prompted for the password of user root in mysql
  7. In mysql run: USE mysql; Update user set host='%' where user='root'; FLUSH PRIVILEGES;

The last line allows the user “root” to connect from any (%) host. It is advisable to replace it with the IP Address of the computer you are trying to connect from. It is also advisable that you create a new mysql user, give that user the required privileges and only allow remote login for that user.

To remove host ‘%’ from root, delete that line in the GUI or run DELETE FROM user where user='root' and host='%'; If you need to add multiple hosts i suggest using the mysql host table and follow the mysql access control reference guide. I also suggest to setup Ubuntus Uncomplicated Firewall to limit access to your server also on mysql port.

Advertisements

Written by kienerj

October 28, 2011 at 13:44

Posted in Database, Linux, MySQL, Operating Systems

Tagged with ,

Connect to Ubuntu from Windows using SSH

with one comment

Intro

If you have read my previous post  you know I had some troubles getting files from Windows to Ubuntu. This was caused by the fact that internet access was blocked by a proxy and I could not use apt-get to install openssh server. Well since this works now, let’s start.

Install OpenSSH Server

In Ubuntu run following command:
sudo apt-get install openssh-server

For further information and configuration please see this. We will continue with the default configuration.

Install WinSCP and PuTTY

  1. Download WinSCP and PuTTY.
  2. Install WinSCP
  3. Move the downloaded putty.exe to your desired folder.
  4. Copy that folder path.
  5. Run WinSCP and on the left menu click on Preferences
  6. Click on the Preferences button
  7. Go to Integration -> Applications
  8. Paste the Path to putty.exe in the according text field and click ok.

Connect to Ubuntu

In WinSCP left-side menu go to Session, select SFTP as file protocol, the Ubuntu Servers IP Address in host name, and the user name and password of a valid Ubuntu user. Then click on “Login”. You should now be connected to the Ubuntu Server and you should be able to easily transfer files between the 2 Computers.

If you want to execute terminal commands, I suggest to use PuTTY either directly by running putty.exe or in WinSCP go to Commands -> Open in PuTTY.

Increased Security

For better security you may choose to use Public key authentication. Follow this guide to set it up and then this guide to simplify future usage.

WinSCP and sudo

Sometimes it can be handy to edit config files through WinSCP and hence your desired editor. To enable file transfer and editing of files with root privileges,  do the following in Ubuntu:

  1. connect to ubuntu terminal with PuTTY
  2. cd /etc/sudoers.d
  3. create new file: sudo vi NoPWForSftp (you may choose a different file name)
  4. add yourUserName ALL=NOPASSWD: /usr/lib/openssh/sftp-server to this file
  5. save file and exit from vi (:w and then :q)
  6. change file permissions to 0440 (r–r—–):
  7. chmod o-r NoPWForSftp removes read privilege for “other” (see Ubuntu Help for further info)
  8. chmod ugo-w NoPWForSftp removes write privilege for everyone
  9. check privilege: ls -l

Now switch to Windows and in WinSCP do the following:

  1. Check “Advanced Options”
  2. If you have a stored session edit it by clicking on “Edit” at the right side of the WinSCP Window
  3. In Environment->SFTP in SFTP server text box enter sudo /usr/lib/openssh/sftp-server
  4. Click “Save” and then try to log in


You should now be able to edit files in Windows in your favorite editor. I suggest to be cautious with this and always create a copy before editing.

Written by kienerj

October 27, 2011 at 10:34

Posted in Linux, Operating Systems, Tools, Windows

Tagged with ,

Installing Windows 7 from an USB Drive

leave a comment »

Preparation

You will need a computer with a DVD drive, Win 7 (maybe vista and xp works too) and a Win 7 Installation disc. I had one for my desktop. If you do not have a Win 7 DVD try Google. As far as I know you can download a Win 7 installer online or ask a friend. Just remember that you use your own product key. You can use a USB flash drive or an external USB hard disk with 5 GB of free space. Attach the USB device to the PC with the DVD drive.

Create bootable Partition

  1. Backup USB drive before doing anything else or use an empty one
  2. Go to Control Panel -> Administrative Tools -> Computer Management -> Disk Management
  3. shrink the partition of the USB drive by 5 GB. right clicking in it and select the appropriate command (something like reduce size)
  4. format new partition to NTFS
  5. right-click in it and mark partition as active

Note if you want to keep nothing else on the drive you can just format it and mark it a active. Above steps can be helpful if you want to but it on a external HDD that already has data on it.

Copy Data to USB Drive

Simple. Just copy & paste the whole Win 7 Installation DVD over to the above created Partition.

Final Words

Depending on the device you are using, there might be some additional steps needed like if you want to use UEFI only instead of BIOS on certain laptops. See this guide as example for further info. It is also advisable to download the Win 7 SP1 installer and install it immediately after the basic installation (assuming your Win 7 DVD does not already contain SP1). You will also need to determine how you can force the netbook/laptop on which you plan to install Win 7 to boot from the USB drive. In case of the Thinkpad X220 you need to press F12 at startup. Please refer to your devices manual or use google.

Written by kienerj

October 26, 2011 at 22:03

Posted in Operating Systems, Windows

Tagged with ,

Ubuntu Server behind a NTLM Proxy

with 2 comments

My Previous Linux Experience

I’m making my first real steps in Linux and immediately ran into a rather annoying issue. My prior Linux knowledge is limited to my time at university where a lot of the computers for the students where running some version of Linux with a GUI. I had a C++ intro class on such computers but most of the stuff I did was with the GUI (web browsing). I was studying biology so that C++ class was about “What is an if statement? What is a for loop?”. You get the idea. My eeePC running Windows XP was going from extremely slow to me almost stomping it and throwing it out of the window. Windows was replaced with Jolicloud, an out-of-the box Ubuntu-based Linux for netbooks. I quickly learned that “sudo” seems to be an important word.

Starting Position

I downloaded 32-bit Ubuntu Server and installed in as a VM in VMWare using its “Easy Install” feature, which means only options I could enter was my user name and password. Install was quick and worked flawless. That was my first surprise. The second one was, that the server console was assuming a keyboard in US layout. So I googled how I could change that and soon got into contact with sudo apt-get update. This failed because of the annyoing ntlm proxy.

Installing cntlm

I tried to follow this Guide (for ntlmaps but shows some basic commands) but quickly ran into problems. I was supposed to install a package but I had no idea how to actually get the file into the Ubuntu Server VM. I lost hours here and the solution I came up with probably fits this xkcd comic I can’t find right now.

  1. download cntlm package on your windows host from here.
  2. Install imgburn
  3. use imgburn to create an iso containing the cntlm package
  4. in VMware under VM->removable devices->CD/DVD in settings option select above created iso
  5. VMware under VM->removable devices->CD/DVD  select connect (VM must be running)
  6. sudo mkdir -p /mnt/dvd
  7. sudo mount -t iso9660 /dev/dvd /mnt/dvd (first check under /dev the actual name of the drive. it was “dvd” in mycase)
  8. cd /mnt/dvd
  9. ls (to determine file name of the package within the iso)
  10. sudo dpkg –install file_name.deb

Configure System and cntlm

You then need to create the file /etc/apt/apt.conf.d/40proxy. Note the “40” is required! Add Acquire::http::Proxy "http://127.0.0.1:3128/"; to that file. Using vi:

  1. cd /etc/apt/apt.conf.d
  2. sudo vi 40proxy (this should create the file)
  3. see this or google for a vi tutorial yourself
  4. press “i” to insert text
  5. press “Esc” to exit insert mode
  6. enter :w to save
  7. enter :q to quit (or :q! to quit without saving if something unexpected happens, it will, believe me especially with a wrong keyboard layout)

After this you need to configure cntlm by editing /etc/cntlm.conf with vi. Enter sudo vi /etc/cntlm.conf and follow instruction on the cntlm home page. If you make a mistake in editing just exit vi with :q! and open it again.

I will have to set username, domain, password, Workstation and Proxy. Workstation is the netbios name (Computer Name) of a Windows PC that can successfully connect through the proxy. In my case my windows host computer name. After you entered these settings run sudo cntlm -M http://www.google.com. This should output auth version and on the next line the  “secure configuration string”. It should look similar to this:


----------------------[ Profile 0 ]----
Auth NTLMv2
PassNTLMv2 C558B...
---------------------------------------

Add the above “code” after “PassNTLMv2” to the cntlm.conf file.  The line is already there you need to uncomment it and replace the existing “code” with the above generated one. Note that in your case it could be PassLM or PassNT. You need to uncomment the appropriate line:


# Example secure config shown below.
# PassLM 1AD35398BE6565DDB5C4EF70C0593492
# PassNT 77B9081511704EE852F94227CF48A793
### Only for user 'testuser', domain 'corp-uk'
PassNTLMv2 C0B9081511704EE8524E4227CF483EB

After that delete the plain text password from the cntlm.conf file! You can leave it empty.

Note that all guides I found suggest to use ntlmaps. This does not work for all NTLM proxies. Therefore I suggest to always use cntlm. Also an alternative option would be to install cntlm on your windows host. The only thing you need to do is let the file /etc/apt/apt.conf.d/40proxy point to the proxy on the windows host:
Acquire::http::Proxy "http://192.168.213.1:3128/";
Of Course you need to adjust the IP address above to fit to your configuration.

Learning by doing

After I finally got this running I realized that I have already got used to the wrong keyboard layout I wanted to change. Also vi was a PITA for me as a windows user. Can’t help you here but you will get used to it as I did. I guess in the end those hours did have quite some training effect and were not completely wasted.

Written by kienerj

October 26, 2011 at 12:53

Posted in Linux, Operating Systems

Tagged with , , ,

Introduction

leave a comment »

This Blog is about solutions to basic IT problems I encounter during my work and private projects. When being confronted with new stuff it often happened to me that I wasted hours for very basic problems that could have been solved within minutes if I had the know-how. After a few month of dealing with something else you come back and realize you forgot half of the solution and waste hours again. While this Blog might help you find a solution it is mainly a personal, easy accessible resource for myself if I ever run into the same issues again.

Enjoy

Written by kienerj

October 26, 2011 at 05:59

Posted in Uncategorized

Tagged with