Like any other creature, snakes need to defend themselves.
While many people think that all snakes are "aggressive," I would seriously beg to differ. Most, in my opinion, are far more defensive than aggressive. From my personal experience, the vast majority of snakes simply try to deter potential threats, rather than actually attacking people. Here are a couple common defense mechanisms.
THE STRIKE!

One of the most common defense mechanisms of many species of snake is the strike, which can include an attempt to bite. Not all snakes that strike actually open their mouths during this technique, so not every species of snake that may strike at you is actually trying to bite you.

For both venomous and nonvenomous snakes alike, striking can be an effective method of deterring potential threats. Unfortunately, some people almost step on snakes without noticing the snake. When the snake sees this as a potential attack, they may strike an unsuspecting person which can lead to the person concluding that they've been attacked by the snake.
THE RATTLESNAKE MIMIC

An impressive number of nonvenomous snakes can actually mimic a rattlesnake. When they feel threatened, they will rapidly shake their tails. The motion itself can be effective, but the tail may also rustle on dry leaves which ends up sounding like a rattlesnake.

I think this form of mimicry is an amazing testimony to the provision of God for all of his creatures, even these little snakes. These nonvenomous snakes obviously don't understand why rattlesnakes have rattles or that rattlesnakes are venomous, but when they feel threatened, that mimic the venomous rattlesnake. Often, it can work, but other times it can lead to their death, as a case of mistaken identity can lead to people thinking snakes that do this are venomous and dangerous.
Anyway, I hope that you learned something. Understanding the world around us and the creatures in it can make everything safer for everyone.
As always, I'm
and here's the proof:
proof-of-defensive-little-snake