Asking for a reference years in advance? I am currently an undergrad and while I am attracted by research and a career in academia, I am on scholarship with a government body in my country and am contractually obligated to complete a 6 year bond in the civil service. I am allowed to complete a Masters degree before then, but not a PhD.

While I have accepted the fact that I won't be able to take the time-tested Bachelors-Masters-PhD route, I still think that there might be a chance that I might want to apply for a PhD program 6 years later, long after I graduate from university.

However, I'm worried about my ability to produce strong academic references by then, especially since my professors would probably have forgotten about me. Would it be appropriate for me to ask my professors to write a reference for me now, while my abilities are still fresh in their minds, so that when I do decide to apply they would only need to make minor adjustments? (And if I do this, should I request to keep the letters myself, or should they be the ones safekeeping them for me?)

It seems a little weird to ask for a reference so far in advance, especially since I don't know for sure if I would be returning to academia. Would I be better off asking them for a references only when I do decide to apply, possibly years down the road? I might perhaps try to keep in contact with them over the years so they don't forget me, though I'm not too sure how this might be done.
There is really no reason not to do this. I would suggest that you either get a reference sealed in a signed envelope, or, possibly even better, have the professor(s), leave a reference letter with the department office (secretaries) with instructions to send it out on request. The recipient will want some assurance against forgery, of course. 

It is usually important that the date that the letter was written be included on it, so that it can be balanced against other, more recent things. 

Unless you have several sealed copies, you will also need a protocol for resealing it and returning it to you. 

When you ask the professors, explain the need as you have done here. I doubt many would refuse. 

Another option is to maintain contact over the years. Some professors welcome this (others may not). Many like to hear from previous students with a quick update on successes and plans.