Git: Restore deleted file
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.
Filed under: Posts | Closed
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.
Filed under: CentOS, HowTo | Closed
Tags: CentOS, FTP, VPS
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.
Filed under: HowTo, Posts, Server, Windows | 3 Comments
Tags: Batch, VirtualBox, Windows
HOWTO: Gnome CentOS VNC Server
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
Filed under: CentOS, HowTo, Posts | 2 Comments
Tags: CentOS, HowTo, Linux, Server, VNC
Well Its Been A While
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.
Filed under: Posts | 2 Comments
2011 in review
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.
Filed under: Uncategorized | Closed
Christmas!
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
Filed under: Posts | 1 Comment
Tags: christmas, evidex
Some Harddrive Tools
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 🙄
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 😀
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 🙄
Filed under: Debian, Posts, Server | 2 Comments
Tags: df -h, harddrive, hdparm, postaday, reserved space, Server, tune2fs