In wood, the fibers are arranged in parallel lines which run lengthwise along the line of growth of the original tree, and this we call the grain of the wood.
The wood may be easily split, sawed, or planed along those parallel lines, or, as we say, “with the grain.”
We use “against the grain” to describe a cut that runs transversely across those lines, whether at right angles or obliquely. It is the long oblique cut that tends to produce slivers; one’s fingers or a plane run smoothly in one direction over such a cut, but snags upon splinters if run in the other direction.
This latter direction is more explicitly described as “against the grain,” and from it we derive our figurative saying, “to go against the grain,” by which we mean to be opposite to one’s inclination or preference, or, especially, to be repugnant to one’s feelings.