Matthew 10:32-33
32 Whosoever therefore shall confess me before men, him will I confess also before my Father which is in heaven.
33 But whosoever shall deny me before men, him will I also deny before my Father which is in heaven.
Luke 12:8-9
8 Also I say unto you, Whosoever shall confess me before men, him shall the Son of man also confess before the angels of God:
9 But he that denieth me before men shall be denied before the angels of God.
These passages are used to teach that without some form of public confession, a believer will be "denied" entrance into Heaven. "Public confession" can then be defined as living a life of obedience to Christ before men, and so they are also used to teach a lifetime of obedience to Jesus is required to not be "denied" entrance to Heaven.
Therefore, it's important to have an understanding of what the Lord is teaching here.
Notice that in the passages, Christ simply says He will "confess" those who confess Him, and "deny" those who deny Him. It requires reading a pre-existent theology of works Salvation into the texts to assert that being "confessed" by Christ means "Jesus will confess that you get to go to Heaven", and being "denied" by Christ means "you will be denied entrance into Heaven". Jesus states no such thing in the passage.
Rather, Christ here is speaking of confessing or denying that someone confessed Him as the basis for whether they have the right to rule and reign with Him, as an exalted position in His kingdom, as we read:
2 Timothy 2:12-13
12 If we suffer, we shall also reign with him: if we deny him, he also will deny us:
13 If we believe not, yet he abideth faithful: he cannot deny himself.
"If we deny Him, he also will deny us" - what? The chance to "reign with him". Either way, we are already "in Christ" (1 Corinthians 1:30), and "members of His body" (Ephesians 5:30), and since "He cannot deny Himself", we are "accepted in the beloved" (Ephesians 1:6), and will never be denied by Christ in the absolute sense, because every believer "shall not come into condemnation" (John 5:24).
The passages in question are just a few of many that testify to the fact that a believer has the opportunity to gain rewards at the Judgment Seat of Christ (2 Corinthians 5:10, Romans 14:10) - an opportunity which can be squandered - resulting in denial of what one could have gained had they been faithful, and the disapproval (shame) of our Savior:
Mark 8:38
38 Whosoever therefore shall be ashamed of me and of my words in this adulterous and sinful generation; of him also shall the Son of man be ashamed, when he cometh in the glory of his Father with the holy angels.
Luke 9:26
26 For whosoever shall be ashamed of me and of my words, of him shall the Son of man be ashamed, when he shall come in his own glory, and in his Father's, and of the holy angels.
Above, we see that what's at stake is shame, in contrast to the confidence that an abiding believer will have when meeting the Lord:
1 John 2:28
28 And now, little children, abide in him; that, when he shall appear, we may have confidence, and not be ashamed before him at his coming.
Clearly, these passages touch on a very similar theme to our passages in question. Nowhere in the New Testament does it teach that all believers will have the same outcome when meeting and being judged by the Lord. What we do certainly matters - just not for Salvation - as that was free (Romans 3:24, 5:15-18, etc.).
Our passages in question, then, are speaking to receiving, or being denied, exaltation in the Kingdom, as a matter of reward, as this article discusses at length.
A further proof that these passages are not in reference to gaining or losing entrance into Heaven is the fact that repeatedly, the Bible teaches that we receive Eternal Life by faith (John 6:47, etc.).
However, faith in Christ is not synonymous with "confessing" Him, as we are given an explicit example where God tells us about people who believed in Christ, yet didn't confess Him:
John 12:42
42 Nevertheless among the chief rulers also many believed on him; but because of the Pharisees they did not confess him, lest they should be put out of the synagogue:
Above, "many believed on Him", thereby receiving Eternal Life (John 6:47), yet, they did not make a public confession of identifying themselves as believers in Jesus Christ.
Similarly, Joseph of Arimathaea, who buried the Lord at his own expense, and therefore surely believed that He was the Messiah, is called a secret disciple:
John 19:38
38 And after this Joseph of Arimathaea, being a disciple of Jesus, but secretly for fear of the Jews, besought Pilate that he might take away the body of Jesus: and Pilate gave him leave. He came therefore, and took the body of Jesus.
Joseph was "a disciple of Jesus, but secretly, for fear of the Jews". This indicates that he certainly believed in Jesus, but did not make the kind of public confession called for by the passages in question, out of fear of persecution by disbelievers.
As the above show, confession of Christ before men, in many places in the world, even until today, can lead to persecution, hatred, and even death for those that do so. It is a good work, but a work nonetheless, and since Salvation is "not of works, lest any man should boast" (Ephesians 2:9), and "not by works of righteousness which we have done" (Titus 3:5), public confession of Christ is not a prerequisite for Salvation.
The fact that confession is not synonymous with "belief", as well as the fact that we are saved, and made righteous, before we even get a chance to confess Christ, is discussed more in the article entitled You Do Not Have to Pray or Confess to be Saved, for those who would like more on the topic.
These verses speak to Christ confessing things about a believer as a basis to determine what their eternal reward will be. They have nothing to do with getting into Heaven, or being sent to Hell.