2 bear encounters
As many other have mentioned keep any food or stuff the bear may be curious about ( not necessarily food, toothpaste, soap etc ) well away from your tent.
I've had 2 close encounters with black bears. One in Ontario that was sniffing at my head, with only the nylon tent wall between us. I saw in the morning the damage he had done to a campground empty garbage box (about 200m away from my site) that had awakened me just minutes earlier before he sniffed me. It was early in the season and the campground was virtually empty of campers and I had no food on my site or in my tent. It was amazing how he could approach in the dark and leave with not a sound.
The second time in the afternoon while I napped in Glacier National Park in a remote area on the shaded porch of an old cabin. I was asleep lying on my stomach on top of my Aerostich Road Crafter suit using it like a mattress, when I felt a touch on the back of my head. I think that both of us were startled when I sat up and yelled at him. I'm sure that I was lucky that he retreated and didn't take a swat at me. He wasn't aggressive and didn't make a sound. I do think that he was just curious. He left the area slowly and allowed me lots of time to takes some pictures. Needless to say my nap was over and I know I was very lucky.
Both times I've yelled F... O.... and used lots of other words and phrases to suggest that the bears leave. Generally bears are looking for something to eat and don't want a hassle so often they can be discouraged away by making lots of noise.
Bear spray might work well; I carry it but I've no experience using it. At least the spray can't kill anyone like a stray bullet could. Personally I wouldn't want to camp within range of anyone who sleeps with a hand gun.