The Rama opens his glosses to the Shulhan Aruch by citing a passage from the Rambam's Moreh Nebuchim about the importance of maintaining awareness of Hashem's watchful eye. Knowing that Hashem is always watching us, wherever we are, will naturally bring us Yir'at Shamayim (fear of Heaven), which will, in turn, help ensure that we avoid wrongdoing, even when we feel tempted to sin.
This concept is stated very clearly in a famous Mishna in Pirkeh Abot (2:1) which teaches: "Look at three things and you will not come upon sin: Know what is above you – a watchful eye and a listening ear, and that all your deeds are written in a book." The most basic thing we can do to avoid wrongful conduct, to overcome spiritual challenges and withstand sinful lures, is to live with a constant awareness that Hashem sees everything we do.
In fact, this was the primary message that the religious leaders would convey to the people in times of crisis to inspire them to perform Teshuba (repentance). The Mishna in Masechet Ta'anit (15a) says that when a public fast day was declared on account of a crisis, such as a drought or plague, the townspeople would assemble and their spiritual leader would speak to them "Dibreh Kibushin." Rabbenu Hananel (Tunisia, d. 1050) explains the word "Kibushin" to mean "concealed," and writes that the leader would reveal the people's hidden sins. This seems very difficult to understand, as it works off the assumption that the town's Rabbi had prophetic insight and knew which sins the people committed in private. The Elya Rabba (Rav Eliyahu Spira, Prague, 1660-1712) explained Rabbenu Hananel to mean that the Rabbi would not actually expose hidden offenses, but would rather remind the people that everything they do, even in private and secrecy, is known to Hashem. This would draw the people's attention to the need to avoid misconduct at all times, as everything they do is seen and recorded.
The Hafetz Haim famously remarked that the advent of video recording helps us understand this concept. It was always difficult for people to fully comprehend the notion that everything we do in life is "filmed' and put onto the record. Now that we have the ability to record, we understand this much more clearly. One of the most basic principles of religious life is that we must live with this awareness, with Yir'at Shamayim, recognizing that Hashem sees everything we do.

