Of course - and it was indeed a great feat.
I hope you don't believe I am trying to negate that (or am falling in "whatsaboutism") but I feel there should be some differentiation: It's one thing to fight for upkeeping slavery or for destroying slavery - but it's quite another thing to stand up for racial equality in the 19th century.
I am pretty sure that you could count the people who desired the latter in 1865 with your two hands...
Hence I deem it possible that not everybody especially not everybody in the non-slave-owning class of the South fought to upkeep slavery.
I found it also very convincing what @Saphroneth, @archieclement and others said about intricate motivations of soldiers to fight.
I think you have to differentiate between political and personal motivations. Everyone who fought for the Confederacy was fighting for slavery, because slavery was the Confederacy's political motivation. The 150 years of denial of that fact has often employed the tactic of trying to substitute the personal motivations of individual soldiers, such as love of country, identification with state, not Union, etc., for the political motivation, the preservation of slavery. That effort continues in earnest today, and when you're not careful to differentiate the two, you are probably going to be misidentified as such an advocate and get push-back.
In addition, your "especially not everybody in the non-slave-owning class of the South" is kinda true, but far from entirely true. Average, non-slave-holding Southerners certainly have different concerns and motivation than people in the slave-owning class (especially large scale slave owners), but that doesn't mean they're not concerned for slavery. Just like Union soldiers could be very resistant to the idea of making slavery/emancipation a political objective, average Southerners could support slavery as the basis of their economy, or the social order that maintains them above a lower class which has been portrayed as subhuman. The whole problem with the slavery question is its multifaceted nature: moral, cultural, social, economic. The same way Northerners might oppose immigration, and a resulting competition for good paying jobs with immigrants who might accept lower wages, average Southerners could oppose anything that endangers slavery. And with extreme, exaggerated sentiments being bandied about (the Union army is an army of abolition (in 1861), freedmen are going to be made your equals, marry your daughters, etc.) general references to defending home and hearth are impossible to differentiate from defending slavery.
However, I'm also not saying personnal motivation cannot deviate from the political. It is not impossible that some Southerners, of any class, could even oppose slavery AND fight for the Confederacy. It would be unusual, but not impossible, and not unheard of.
Then there's the whole TOV matter (though I find it claimed by some more than genuinely expressed by others)…
I even feel the need to get even more on everybody's nerve: could it be that in their prevalent repudiation of racial equality northern and southern soldiers shared a trait?
And recounting how strong northern and southern sentiments are visible even here in this forum I am still convinced that this factor cannot be left out of calculation.
Get on their nerves, mine included (though this particular thought in no way gets on my nerves, as I share it). I may not agree with what you have to say, but this a forum, say what you feel (to paraphrase Patrick Henry). We spend so much time debating the motivations of the Confederacy, we don't spend enough time on those of the Union, so you may not have realized how many people agree with this thought.
Before the war, the anti-slavery movement was as complex as slavery itself. The only ones who come close to the proper moral outlook were the abolitionists, a definite minority in the North. Much of the anti-slavery movement was concerned with the welfare of the white working man:
"
I make no war upon the South nor upon slavery in the South. I have no squeamish sensitiveness upon the subject of slavery, nor morbid sympathy for the slave. I plead the cause of the rights of white freemen. I would preserve for free white labor a fair country, a rich inheritance, where the sons of toil, of my own race and own color, can live without the disgrace which association with negro slavery brings upon free labor. I stand for the inviolability of free territory. It shall remain free, so far as my voice or vote can aid in the preservation of its character.
. . . O, for the honor of the North for the fair fame of our green hills and valleys, be firm in this crisis be true to your country and your race. The white laborer of the North claims your service; he demands that you stand firm to his interests and his rights; that you preserve the future homes of his children, on the distant shores of the Pacific, from the degradation and dishonor of negro servitude. Where the negro slave labors, the free white man cannot labor by his side without sharing in his degradation and disgrace." – David Wilmot, 1847, while introducing what would become known as the Wilmot Proviso
And then there's the gray area; those, like Lincoln, who found slavery morally repugnant, because of its degrading effects upon the slaves, but still opposed interference with it where it already exists, and who, like Wilmot, distanced himself from abolitionists.
This is also how you get both opposition to slavery and opposition to the immigration of any African American, slave or free, into many Northern states. Actual laws banning EITHER. The ONLY way slavery ends in the US when it did is because it threatened the Union itself, that being the source of relative equality and prosperity for average white Americans. Certainly, seeing African Americans fight as bravely and effectively as anyone in the ACW generates a desire to extend them a degree of equality, especially within the defeated South (part justice, part NIMBY). Johnson's attempt to quickly restore the Confederate states, coupled with continued and growing Southern intransigence, would magnify that effect. Hence, Radical Republicans gain ascendancy for a period of time. But the primary Northern concern from beginning to end is clothed in ****, although perhaps more subdued for a time. Eventually, the equality of freedmen is abandoned for that same primary concern, and the Compromise of 1877 ends Reconstruction and the Civil War era.
Similarly, in the midst of fighting against what was often described as an attempt at their own enslavement, the Revolutionary War era would initiate abolition, emancipation, and manumission, at least as far as any meaningful scale goes. Even then, however, it's rather complex. How much early anti-slavery sentiment is prompted by concern for the slaves themselves vs. concern over the embarrassment of a country supposedly established under the banners of freedom and equality continuing to hold on to slavery? It's certainly a complex mix. That situation continues; compromises are made time and again; eventually abolitionism becomes radical and later unites with growing Free Soil sentiment. Follow the progress, from Liberty party, to Free Soil party, to Republican party. Only with such sentiment, and reactions to the extreme measures employed by slavery proponents against radical abolition, and to maintain slave-state parity in the Senate, do you get to a Civil War that ends slavery in the US in 1865, for a very complex mix of reasons, which ultimately are not entirely all that altruistic. Freedmen suffer another 8 to 10 decades of institutional inequality, North & South.