We have been carrying dry beans and rice, barley and oats on our boat for years. We just drop a bay leaf into each container. No bugs.
I use bay leaves, usually a few in each container, and then re-use them until they are stale. I have only had bugs twice in ten years, and one of the times the rice was already old.
If people rotate, most grains and legumes will easily last three years that way.