Here’s a handy alias I nabbed from somewhere, which restores a file accidentally deleted by a commit.

 

git config --global alias.restore '!f() { git checkout $(git rev-list -n 1 HEAD -- $1)~1 -- $(git diff --name-status $(git rev-list -n 1 HEAD -- $1)~1 | grep '^D' | cut -f 2); }; f'

 

In future, just use git restore myfile.ext to restore your deleted file.


In this how to we’re going to setup an FTP server on our CentOS machine. Now, before we begin, a word of warning. FTP is inherently insecure and may cause your server to become vulnerable to attack. Consider using FTP with SSL, or SFTP, FTP over SSH. Follow this tutorial at your own risk.

Install the package

Use the following command to grab the vsftp package from the repos and install it.

sudo yum install vsftpd

Configuration

By default, vsftp comes reasonably securely configured. That being said, it does allow anonymous logins, which are useful if you want to distribute files openly, but not if want security. We’re going to disable that. We’re also going to restricted users to their own home directories, so that if one user account is compromised, a hacker shouldn’t be able to access the whole server.

To do this, we’re going to edit the configuration file using:

sudo vim /etc/vsftpd/vsftpd.conf

Within this file, change the following settings to the values below.

anonymous_enable=NO
local_enable=YES
chroot_local_user=YES

This will prevent anonymous logins, and restrict users to their own files and directories.

Finally, let’s restart the server.

sudo service vsftpd restart

To ensure it runs at boot up, we’ll need to use chkconfig

chkconfig vsftpd on

That’s it! You should now be able to login to the FTP server using an application such as FileZilla or even through a web browser, by entering

ftp://your.serveraddress.com

and loging in with valid credentials.


Here’s a quick and simple solution to getting a VirtualBox VM to start on boot in MS Windows.

Create a new batch script with Notepad. Enter the following code, changing to include the name of your VM.

cd "C:\Program Files\Oracle\VirtualBox"
VBoxHeadless --startvm name_of_your_vm_here

Save and close your file. Now click and drag it from where you saved it, over the Start Menu and drop it into the “Startup” folder. Now, that script will be executed on startup.

That’s it! Reboot and check that your VM has started running. It will be headless (ie you won’t be a VBox window) which is great for VMs you want in the background. However, you will still have a command prompt open.


This tutorial will outline how to install and configure a VNC Server on CentOS, similar to the Ubuntu VNC HowTo I did a while back.
This is particularly useful on headless servers, where you or other users still want to interact with a GUI.

Install the Packages

To install the VNC Server, open a terminal, and run the following command as root. (Use the su command to login as the root user, or, if you have it installed, use sudo.)

For CentOS 5:

yum install vnc-server

For CentOS 6:

yum install tigervnc-server

However, we now also need to install a Window Manager. In this tutorial, we’ll use Gnome, but you could use XFCE, KDE or whatever other WM you like.

To install Gnome and it’s requirements, run the following command as root.

For CentOS 5:

yum groupinstall "GNOME Desktop Environment"

For CentOS 6:

yum groupinstall "Desktop"

Configuring Un-Encrypted VNC

First we need to edit the config file to include all the users who will have VNC desktops.

To do that, edit /etc/sysconfig/vncservers to add the following lines;

VNCSERVERS="1:user1 2:user2 "
VNCSERVERARGS[1]="-geometry 640x480"
VNCSERVERARGS[2]="-geometry 1024x768"

The VNCSERVERARGS array allows you to give each user’s VNC session different arguments. Here, user1 has a desktop resolution of 640×480, whereas user2 has a resolution of 1024×768. Read the vnc-server man pages for a full list of all the arguments you can provide.

Now, we must give every user a vnc password. To do this, we su into their account and run vncpasswd as follows. You can omit the first command (useradd) for existing users.

useradd user1
su user1
vncpasswd

This will create a .vnc directory in the user’s home, which will contain their passwd file. Do this for every user in the config file.

Almost done. Let’s check that the vnc server starts and stops correctly. This will check to make sure that you’ve correctly created the .vnc directory for every user.

/sbin/service   vncserver start
/sbin/service   vncserver stop

Finally, let’s startup the vnc server.

/sbin/service   vncserver start

Now you should be able to connect using a VNC client to your_server_ip:590X where X is the desktop number you want – eg 1 for user1, 2 for user2 etc

 

To Add

  • Encrypted VNC Server config
  • Detailed connecting instructions
  • Starting server at boot

Long time so see eh?

I’d like to say that I’ve some great reason that this blog has been left so derelict over the last two years, but that’s not entirely true.

I’ve gone along way, and done a lot of different things over the last two years. I started college, and am now in my second year of Computer Science. I’ve studied PHP, HTML5, Java, Python, Javascript and more.

What I’m trying to say is, that I should have plenty of new material to cover. I’d also like to thank everyone for still visiting, leaving comments and finding the material here useful. I’m truly surprised that two years since my last post, this blog is more popular than when I left it.

So I think it’s time to resurrect this blog. There’s a lot of spring cleaning to do, things that need to be updated, so bare with me over the next week or so.

For now, here’s a screen shot to whet your appetite.

crunch-jan-13


2011 in review

01Jan12

The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

The concert hall at the Syndey Opera House holds 2,700 people. This blog was viewed about 58,000 times in 2011. If it were a concert at Sydney Opera House, it would take about 21 sold-out performances for that many people to see it.

Click here to see the complete report.


One of the handiest features of Compiz is having multiple workspaces, anywhere from 2 to 1024 (for the extreme multi-tasker).

By default, you can switch through workspaces by using Control + Alt + Left/Right. However I find it’s far quicker to switch workspaces by just spinning your mouse wheel.

To do so (presuming you have compizconfig-settings-manager installed) go to Desktop > Viewport Switching.

Click on the “Desktop Based Switching” tab, and change “Move Next” to Button 5, and “Move Prev” to Button 4. You’ll now be able to flip between workspaces with your mouse wheel :)

Personally, I also like to go to Desktop Wall, and click on the “Viewport Switching” tab, and define “Non-Sliding Windows” to


(name=gnome-panel) & name=desktop_window

This prevents Gnome-Panel and the Desktop Background sliding, making the windows just slide over them :)

 


Christmas!

24Dec11

Tux, the Linux penguin, wearing a Santa Hat

Even though I’ve not updated my blog in quite a while, a suprising number of people drop by every day. Seeing as it’s the season that it is, I just wanted to wish ye all a very Merry Christmas.

Eat, drink, be merry, watch re-runs of the Titanic movie, however you celebrate, just enjoy!

Thanks for visiting, and making this blog possible! Be sure to drop by in the new year, for some great new HowTos!

~Evidex


My HowTo on fixing an EXT partition in Ubuntu is by far my most popular post, pulling in new visitors everyday. The only reason I wrote it is because it was something that happened to me now and again.

But what about dual boots? What happens when your NTFS drive goes beserk, and you only have access to your Ubuntu install? Well, finally, I’ve come across a solution.

Now, before we begin, this HowTo assumes that your Ubuntu install is working as normal, and that the NTFS partition isn’t essential to Ubuntu. It’s also possible (though I’ve not yet tried) to follow this HowTo using Parted  Magic.

First, we need to find out what partition we are dealing with. To do this, open a terminal and type;

sudo fdisk -l

That’ll give you something like this;

Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2709a320

 Device Boot Start End Blocks Id System
/dev/sdb1 * 1 19457 156288321 7 HPFS/NTFS

/dev/sd1 is in this case the NTFS drive we’ll be working with. Obviously change this to whatever yours is. If your partition isn’t listed here, or appears to be the wrong size, you’ll need to use TestDisk.

Next, you need to install some software called “ntfsprogs”. You can do this through Synaptic or on the command line using;

sudo apt-get install ntfsprogs

There’s just one last step.

sudo ntfsfix /dev/sdb1

With any luck, you should see the following;


Mounting volume... OK
Processing of $MFT and $MFTMirr completed successfully.
NTFS volume version is 3.1.
NTFS partition /dev/sdb1 was processed successfully.

And that’s it! Go try to mount you NTFS partition, and it should work again as normal. If not, feel free to leave a comment below.


Seeing as I’m just rebuilding my server at the moment, I’m starting to remember a number of commands that I’ve not used in quite a while. Here’s three dead handy commands that deal with hard drives and filesystems. Seriously, how I ever forgot them, I’ll never know :roll:

The first is the simplest. It shows you how much space you’ve used, and have free, on every storage medium attached to your machine. It’s four characters. Gotta love the simple things in life :D

df -h

If you did it right, you should see something like this;

Filesystem Size Used Avail Use% Mounted on
/dev/sda2             6.0G  901M  4.8G  16% /
udev                  243M  164K  243M   1% /dev
/dev/sdc1             917G  615G  293G  68% /mnt/1000
/dev/sdb1             459G  199M  454G   1% /home

The next is a tool that does far too many things for me to understand, including some things which will DESTROY your data and maybe even physical harddrive. So be careful what you type. I however, use it as a performance tool.

hdparm -Tt /dev/sda

Obviously, change /dev/sda to whatever drive you like (you can find it with df -h ;)). Again, if you’ve done it right, you’ll see something like this;

/dev/sdb:

Timing cached reads: 792 MB in 2.00 seconds = 395.34 MB/sec
 Timing buffered disk reads: 340 MB in 3.00 seconds = 113.16 MB/sec

The first reading (-T), shows, according to the man page, “is essentially an indication of the throughput of the processor, cache, and memory of the system under test”. The second reading (-t) is the more true speed of the drive, the actual speed a file can be read from the disk, without any caches. So obviously, this little command is great for those like me, who love comparing various computers, disks and setups.

The last command is another multipurpose tool, which deals with ext filesystem settings, rather than harddrive settings as hdparm does.

However, before I tell you what it is, we must do some homework. Ext based filesystems (and a few others) reserve space on the drive for the system. It’s main use is that when you accidentally “fill” the drive, there’s still some secret space left over for the system to use, preventing it from freezing up. By default, it’s set to 5%. Now on a root drive, that’s a good setting to have, but it’s not quite necessary on a drive that’s simply being used to store bulk data. In such a case, it’s safe enough to reduce that secret reserved space back to 1% in order to win back some previous MBs.

Without futher ado, here it is;

tune2fs -m 1 /dev/sda1

Again, change /dev/sda1 to whatever you need yourself. The 1 after the -m flag donates setting a reserved space of 1%. For example, on a terabyte harddrive, changing from the defaults of 5% to 1% should give you a gain of 37GB or so.

Right, well that’s it for now. Hopefully, I’ll keep posting bits and pieces. No promises though :roll:




Follow

Get every new post delivered to your Inbox.

Join 69 other followers