Labels

Wednesday, August 14, 2013

How to setup a reverse ssh tunnel

Ever wanted to know how you can ssh into your work desktop/server? Well do not worry any longer.....
    • All you need to do is create a reverse tunnel from your Work Desktop/Server to your home server.

    • ssh -nNT -R 5000:local_server:22 username@remote_server
    • Now from the remote_server run this
      ssh -p5000 localhost.... now we are in our work desktop/server.
    • Lets brake this down a bit..

    • The -n option Redirects stdin from /dev/null. This must be used when ssh is run in the background.
    • The -N option does not execute a remote command. This is useful for just forwarding ports.
    • The -T option disables pseudo-tty allocation.
    • The -R option does tha job of setting up the reverse tunnel.
    • Port 5000 is the port that will be listening on the remote_server (this can be any random port over 1024, if you want to run this as a non-root user).
    • local_server is the desktop/server that you are creating the connection from.
    • Port 22 is the port that you are making the ssh connection to.
    • user_name@remote_server is where you are making the ssh connection to for the reverse tunnel.
    • We need to make sure we keep this connection open.
    • In /etc/ssh/sshd_config we need to make sure this is set TCPKeepAlive yes.\


This page was stolen from somewhere else, I can't remember where. Sorry to the original author..

Running a script as root

The problem:

In theory, running a script as it's owner (in our case root) is simple, all you have to do is set the 'setuid' bit (sometimes mistakenly called the 'sticky' bit) by using 'chmod 4755' (or chmod 4***, depending on what mode you need). The problem is, that the 'setuid' bit functionality has been disabed on most Linux based distros for security reasons. This affects only scripts, not compiled code which should still work.

Solutions:

binary wrapper

The 'setuid' bit still works for compiled files. So what you can do is write a little c wrapper that will execute the script you want to run as root.
#include 
#include 
#include 
#include 

using namespace std;

int main(int argc, char* argv[]) {
    setuid( 0 );
    string cmd = "/opt/local/cmd.sh";
    for (int i = 1; i < argc; i++) {
        string arg (argv[i]);
        cmd += " ";
        cmd += arg;
    }
    int exitcode;
    exitcode = system(cmd.c_str());
    return WEXITSTATUS(exitcode);
}

Safe this as 'runscript.c', then compile and do the following:
gcc runscript.c -o runscript
sudo chown root:root runscript
sudo chmod 4750 runscript
You should now be able to run this command as root.

sudo wrapper

Add the following line to your sudoers file, with 'group' being the group you want to give access to your script.
group    ALL = NOPASSWD: /path/to/script
Then write a wrapper, executing you script with sudo.
sudo /path/to/script
Also your script will have to perform a 'setuid(0)' to make sure that all child processes are executed as root.

A couple of things to note:

  • it's not enough to do 'chmod 4***' on the binary, you also have to use 'setuid' inside the code.
  • an additional problem on Mac OS X is, that by default the 'setuid' bit is disabled on NFS mounts.


x forward session with xdmcp

XDMCP allows logging into a remote host, but displaying the desktop on your own host.
1) edit /etc.gdm/custom.conf
[xdmcp]
Enable=true

[security]
DisallowTCP=false
AllowRemoteRoot=true
2) restart X (telinit 3; telinit 5)
3) login as root and run:
gdmsetup
4) On the remote tab, change 'style' to 'same as local'
5) On the security tab, tick 'allow local system administrator login' and 'allow local system administrator login'
6) restart X

To test, log off your host, and press F10 in the login GDM login window. You can enter the name of the remote host to login too here.

Forward user x sessions

When logging into a remote host as root, you lose the ability to forward x sessions after an su to another user.
To allow x-forwarding after you perform an su, you need to request the cookie for the current server:

ssh root@somehost

xauth list
returns:
 somehost.somedomain/unix:10  MIT-MAGIC-COOKIE-1  d9fc3512df83a70ea8054dff21f58e28

Now, su to the user:
 
su - someuser

xauth add somehost.somedomain/unix:10  MIT-MAGIC-COOKIE-1  d9fc3512df83a70ea8054dff21f58e28
now x apps will forward correctly - test with xterm.

Friday, July 26, 2013

20MB Boot Floppy Image

These days BIOS and IPMI (and other no doubt) updates are getting larger.

Most of the boot floppies you can download are 1.4MB which makes upgrading some firmware modules difficult when PXE booting as the images wont fit.

I was able to build a 20MB image using these commands.

wget http://itblog.su/downloads/W98SE_R.img
rpm -ivh ms-sys-2.2.0-1.el5.rf.i386.rpm
dd if=/dev/zero of=floppy.img bs=1024 count=20000
mkdosfs floppy.img
ms-sys -1 -f floppy.img
mount -o loop floppy.img /mnt/floppy
mount /W98SE_R.img /mnt/dos
cp /mnt/dos/* /mnt/floppy/
umount /mnt/dos/

IPMI Upgrade through PXE

The Supermicro nodes have IPMI modules built in. These can be accessed using either the dedicated IPMI NIC, or by sharing the primary NIC with the host OS. We have chosen to use the shared option to reduce cabling.

Out of the box the machines came with a version of IPMI that didn't work for us so we had to update the IMPI firmware using the yafukcs utility.

The standard approach is to perform this via USB key but due to the number of nodes this is not practical. Therefore I created a freedos image containing the required firmware and configuration files that can be PXE booted to the nodes in one go.

This process saves around 4 days of manual labour. We still have to manually gather the MAC addresses of the new IPMI interfaces and add them to DHCP, but there are ways we can speed this process up using FDB in the switches.

Once we have our bootable image we add the required firmware update files

autoexec.bat
@echo off set PATH=.;\;\LOCALE
echo Using US-English keyboard with US-English codepage [437]
ipmicfg.exe -m
1.bat
2.bat
fdapm coldboot 

1.bat
yafukcs.exe -full X8DTT_~1.IMA 

Although it was quicker to update only the required modules using the -auto option we had better success with re-updating all the modules using the -full option.

2.bat
ipmicfg.exe -m
ipmicfg.exe -dhcp on
ipmicfg.exe -dhcp
ipmicfg.exe -r 

Once we run the update we configure IPMI with ipmicfg.exe to DHCP and very importantly perform a BMC cold reset. Then we add the image to the PXE config on our boot server (puppet in this case)

The relevant lines in the /var/lib/tftpboot/pxelinux.cfg/

LABEL Supermicro IPMI Firmware Update
KERNEL /sysresccd/isolinux/memdisk
APPEND initrd=/sysresccd/isolinux/floppy.img 

And copy the image (floppy.img) to /var/lib/tftpboot/sysresccd/isolinux/

We can now boot into the new image to ensure it works by selecting the new menu option from the PXE boot menu.

Sunday, January 23, 2011

CCOMTB - 2011 - Round 1

Status: Finished
Grade: B

What a race, and what a turn out! It looked like there were about 15 people in A grade alone. Great Nobmob turn out too, hopefully those that haven't been before can see what a great race it is and will attend some more. Well done to Ray for what looked like 5th place in A grade - what a demon. Logan, hope your cuts heal OK, they looked pretty nasty but nothing a pommy victory at the cricket wouldn't solve eh? Eye-wink

I started at the back of the pack in B grade, and had great fun once I decided to back the first lap pace off a bit. No idea what place I came, Gazza said I came in after him but I can't see how, I felt like I was pretty coozie on the last 2 laps. I was expecting to blow up hard given that I've been zero training since the new little man was born (who has great quad development at 7 weeks old incidentally) but I felt in pretty good shape. I had a chance to ride behind a 29er for some of it, those bikes certainly seem to make sense at a track like Ourimbah, he was certainly rolling over the rough stuff and making it look easy.

No events really.. big traffic jam at the top of the drop on the first lap, looks like someone didn't ride the lap before hand Sticking out tongue, I lost the rear end on Small meadows, I couldn't get rid of the smile in the grave yard, oh and I loved the end of the the roller coaster now that it misses magic carpet. It sounds like magic carpet is about to get some pretty choice upgrades - can't wait for round 2.

Thursday, December 23, 2010

CCOMTB - 2010 final results

For my record keeping, the final results have been posted up:

Final results : http://www.ccomtb.com.au/results/Final%20XC%20Rankings%202010.pdf

What a great year, never thought I could get first place in B grade, but I guess showing up to as many races as possible really pays off. I'm really going to try and do some next year as well.

Edit: Managed to get to the first round of CCOMTB XC 2011, and picked up my trophy Laughing out loud

Monday, November 01, 2010

CCOMTB - Club Race - 2010 Round 10 - 6 hour Final

Status:
Finished
Laps:
9
Time:
06:20:16
Position (Overall):
8

Hard. Phew, what a race.

This was my last for a while with a baby on the way my races are taking a back seat. This was also the last race of the CCOMTB season and I managed to do all but one so wanted to go well. I started too hard after telling eveyone I was going to go easy and realised I was in for a hard race by the end of lap two. I just couldn't drink enough water and by lap 5 was showing the signs of dehydration. I pretty much had a rest after every lap from then on. Timing was good though, managed to time the cut off just after passing through the gate so squeezed another (very slow) lap in. On that lap I ran over a snake and narrowly avoided a rider coming the wrong way at the bottom of browns! The scare almost made me forget the cramps.

How some people do solo 8 hours around here I don't know.

The CCOMTB season has been great, recommended to everyone for good hard racing, friendly people and of course some of the best trails around.

Monday, September 13, 2010

CCOMTB - Club Race - 2010 Round 9 REVERSE LOOP

Status: Finished
Laps: 3
Race Category: B Grade Men

Great but hard race. Like a different track in reverse, but really good fun, and some big hucks. Still waiting for the result but I'm told I was 3rd or 4th.

http://connect.garmin.com/activity/48763936

Wednesday, August 25, 2010

CCOMTB - Club Race - 2010 Round 8

Status:Finished
Laps: 3
Time: 01:45:07
Race Category: B Grade Men
Position (Category): 4

Great race this weekend. Come on Gazza, the championship's yours to loose now.

Monday, August 09, 2010

JetBlack 12 Hours WSMTB Race

Team:
Mixed Nuts
Status:
Finished
Laps:
23
Time:
12:25:52
Race Category:
Masters/Team/4
Position (Category): 1

Entering this race with man down might have been seen as in a negative light but as we won our class in the most recent 24 hour JetBlack race we thought we had a good chance of at least making the podium of Masters 4s. I was in a team with Carlgroover and Whisperer. Carlgroover was positive we had first place in the bag before even starting!.

We started off in the lead and kept it all the way through. There isn't much to say about our laps really, they were pretty uneventful other than the usual things that happen at races. Steve had a puncture after putting a hole in a side-wall on one of his laps but fixed it in record time so we only lost around 8 minutes I think. On my first lap I got lost twice (which can be seen from my GPS track) which brought me in a couple of minutes slow. There were a LOT of people getting lost on that lap, I do think the signs could have been better, yellow arrows on a white back ground are hard to read at speed.

I really liked the track. For me there was a good mix of everything, and I think the longer fast stretches worked well with my current "training program". The downhill was great fun and Whisperer manages to set up camp with a great view, providing some excellent near misses, some riders getting very loose over a jump next to a barb wire fence. I did see one off there, some chap on a crosser who was thankfully ok.

We never backed off as the second place team were pretty close after the puncture but obviously we are all happy with the result considering there were only 3 of us.

Kudos to Gav for coming in third on the first lap and setting the fastest night lap (I think) of 27 something. No mean feat on that track.

Man it was cold but the vibe around the massive fire was great. All in all, a top event :)

http://connect.garmin.com/activity/43562981

Friday, May 28, 2010

CCOMTB - Club Race - 2010 Round 7 NIGHT RACE

Status: Finished
Laps: 4
Time: 01:12:27
Race Category: B Grade Men
Position (Category): 7

Hard at night when you have rubbish lights.

Sunday, May 02, 2010

Dirtworks Classic 2010

Status:
Finished
Time:
05:28:28
Position (Overall):
198
Race Category:
100km Male Masters
Position (Category):
57

Anyone see that inconsiderate idiot that cramped on the canoe bridge and held up stacks of people for about 5 minutes? That was me Sad
Sincere apologies to anyone behind me. There really was nothing I could do, movement was not an option, I have never had cramp that bad.

I thought I was on for a cracker of a time up till then too, as it was, with the 5 odd mins. lost on the bridge and from having cramp for the remainder of the ride, loosing loads of places etc. I was only in 2 mins. slower than last year. I suppose I could be pleased with that, if it wasn't for the shame.

Note to self; one 70kay training ride on the road is not enough for the DW.

Hats off to all that took part this year, you are all legends.

Sunday, April 18, 2010

CCOMTB - Club Race - 2010 Round 4

Status:
Finished
Laps:
3
Time:
01:37:01
Race Category:
B Grade Men
Position (Category):
11

Track was perfect today, nice and tacky mostly everywhere. Happy with the 1:37 mins in light of the lack of training recently, I don't think that is far off my old times. It was good to get some hill training done after the race as well.

Well done to Steve and Gazza for a nobmob 1, 2. Sorry I wasn't around to make it a 3 as well, but this is one hellish competitive race Smiling

Sunday, March 21, 2010

CCOMTB - Club Race - 2010 Round 3 DEMTEL CHALLENGE

Status:
Finished
Laps:
3
Time:
01:37:53
Race Category:
B Grade Men
Position (Category):
11

Actually I shouldn't call it hell, it was completely expected. It really felt like there was a lot of climbing for this race but in fact it was only 694m in total. The downhill section after Demtel was fine, I was expecting all sorts of surprises but most people I saw took it all very slowly and it was all pretty straight forward. I got a pretty rubbish start but I'm not going to use it as an excuse, I just need to do more interval training.

Well done to the fast guys that finished in front of me (how competitive is this little group getting!), and bad luck to the DNFers.

Sunday, February 28, 2010

CCOMTB - Club Race - 2010 Round 2

Status:
Finished
Laps:
3
Time:
01:37:18
Race Category:
B Grade Men
Position (Category):
12

Due to injury I haven't been training for 2 weeks and it really showed today. I found it hard to keep with the leaders on the first lap and I wasn't enjoying the pace one bit, None the less my HR was often up around 97% so I wasn't slacking off. I made a couple of silly mistakes and was getting a bit loose so I was much happier when I backed off to around 90% HR.

Bad luck to Gazza for getting a flat front tyre on the first lap. When I got to him he was about the throw the towel in but I chucked my seat bag at him and yelled something about thinking about the points. I only found out at the end he didn't even have a pump!! Sorry Gazza, I tried Smiling

Great to see Wazza racing the whole last lap bashing handlebars with some young gun. At the end he looked like he had given it everything, they were glued together on the line.

There were a lot more riders this weekend so I'm not expecting top ten, but it's good to have my race number for the year - 27 Smiling

Temp: Around 28 I think.
Hydration: 1.2 Litres
Energy: 1.5 Gels (not enough)
Track: Just about perfect.

Monday, February 08, 2010

JetBlack twenty four hours Sydney 2010

Team: Salty Nuts
Status: Finished
Laps: 28
Time:24:22:48
Race Category: 24 Male Team 4 40+
Position (Category): 1

This was always going to be a competitive team, just look who is in it. From the start I thought we had a good chance at a podium finish, and finding out on Friday that I wasn't able to compete in the Mont 24 due to work commitments I was ready to give this race everything I had.

From the start I was a bit worried about the track, it sounded as if it would suit road riders more than technical riders (I consider myself the later although with my recent dosage of training on the road that could be argued I guess) but actually the circuit worked really well. Yeah the hill was painful but then they always are and it was easy to put your head down and grind it out. The gully was great fun and you could carry some pretty decent speed through there. I had a couple of stacks on the off camber roots on the new section of single track that annoyed me a bit but somehow didn't slow me down and in the end all of my laps where within a few seconds of each other (apart from the madness before it the race was pulled for the night. Yes it rained, it rained a lot. Rocky trail made the right call to call it when they did, sending people out at night in that rain would not have been a popular call, it was getting dangerous.

This is the first race I have used my heart rate as my "speedo" and the technique worked well for me. When you get fatigued it's easy to drop the pace without realising it but watching the heart you can keep the same level of effort at all times, even down hill. This works best of all when you get to the top of a climb when most people back off, this is the perfect time to bang it down a few gears and get some speed up.

I wasn't THAT surprised we were leading out category but when I heard we where second in open fours that was quite a shock. John had already made his mind up we were going to win the whole thing and was going after getting first overall, I think he was racing Jason English! The rest of us where along for the ride. Each of us rode as hard as we could every lap, there was no pace setting, it was just one long sprint. No mess ups, not too many crashes (despite Steve_01 pushing his luck on the cabin steps), just hard riding. It felt great to be on such a quick team.

Great vibe out on the track, lots of chatting (although none from my fatigued lungs). And a nice last lap dual with an unknown rider right up to the finish line. I hadn't been passed all weekend and was damned if I was going to let that happen on the line. Competitive? Perhaps I was in the right team after all Smiling

Highlights:
Not being passed during the event
Food and Hydration spot on
Consistent Lap times
Brilliant team
My first first place (I think)

Lowlight: Getting home to find my house had been flooded Sad

Well done to "Pissed and peddling" (hope your tooth mends well Blondie). Thanks to the roadies that made it out on both days, great to see you make the effort and appreciate the support even if I did more or less blank you on the road, race face was firmly attached. Thanks to Whisperer for pulling the great team together and doing all the organising etc.. Thanks to Steve_01 for stepping up as the gun and handing me that last unexpected lap. And thanks to John for the advice, comedy and endless reminders that he has some kiwi in him somewhere. Eh Bro?

Results