The story of Jesus's encounter with the rich young ruler is told in Matthew, Mark, and Luke. It's a story that is occasionally used by works Salvationists as a proof text for the idea that you must keep the commandments or otherwise follow Christ to some unspecified degree in order to get to Heaven.
This is especially absurd, given what is actually said in the passage, as this would require an invalidation of hundreds of New Testament verses, but when did that ever give pause to these clowns?
Notice that the rich young man starts with the presupposition that he must do something good in order to get Eternal Life:
Matthew 19:16
16 And, behold, one came and said unto him, Good Master, what good thing shall I do, that I may have eternal life?
Mark 10:17
17 And when he was gone forth into the way, there came one running, and kneeled to him, and asked him, Good Master, what shall I do that I may inherit eternal life?
Mark 18:18
18 And a certain ruler asked him, saying, Good Master, what shall I do to inherit eternal life?
As can be seen by what the man says, particularly in the Matthew account, he has set in his mind the idea that he must do a "good thing" to get to Heaven.
Christ's response immediately begins to chip away at the young man's misconception. He gives the young man a paraphrase of Ecclesiastes 7:20 (later quoted in Romans 3:10), telling him that only God is good. That means the young man isn't good, hasn't been good, and won't be good in the future.
Then, Jesus tells him to keep the commandments. By telling him this immediately after essentially telling the young man that he isn't good, Christ again is taking shots at the young man's preconceived idea that he must do something good to get to Heaven. Since the man has not been good thus far, the task is intended to overwhelm him:
Matthew 19:17-19
17 And he said unto him, Why callest thou me good? there is none good but one, that is, God: but if thou wilt enter into life, keep the commandments.
18 He saith unto him, Which? Jesus said, Thou shalt do no murder, Thou shalt not commit adultery, Thou shalt not steal, Thou shalt not bear false witness,
19 Honour thy father and thy mother: and, Thou shalt love thy neighbour as thyself.
Mark 10:18-19
18 And Jesus said unto him, Why callest thou me good? there is none good but one, that is, God.
19 Thou knowest the commandments, Do not commit adultery, Do not kill, Do not steal, Do not bear false witness, Defraud not, Honour thy father and mother.
Luke 18:19-20
19 And Jesus said unto him, Why callest thou me good? none is good, save one, that is, God.
20 Thou knowest the commandments, Do not commit adultery, Do not kill, Do not steal, Do not bear false witness, Honour thy father and thy mother.
Jesus essentially tells him to "be good" after having told him that there is "none good" - this alone should've been enough to "straighten out" the misgivings of the young man and show him his helpless condition to do some "good thing" to make it to Heaven.
But in another sense, Jesus gives the young man a genuine answer as to how to be his own savior. If the young man keeps the Law (which Christ already told him he hasn't), then he will genuinely merit Eternal Life (Romans 2:7). Unfortunately, no one has ever done this or saved themselves this way (Romans 3:10-12), hence the need for Jesus Christ fulfilling the Law in the first place.
Therefore, Jesus is using the Law for it's intended purpose - to give the young man knowledge of his imperfection (Romans 3:20), and therefore bring him to the Savior (Galatians 3:24).
The young man doesn't get it. Christ declaring him not to be good goes over his head, and he responds with a lie:
Matthew 19:20
20 The young man saith unto him, All these things have I kept from my youth up: what lack I yet?
Mark 10:20
20 And he answered and said unto him, Master, all these have I observed from my youth.
Luke 18:21
21 And he said, All these have I kept from my youth up.
Now, I should state here that the man probably kept them to a degree, but so does everyone else. That degree is less than perfection, and therefore he's still not understanding the absolute sense of Law keeping and the absolute sense of good which Christ is referring to.
Noticing that the young man isn't getting it, Jesus issues a statement that forces the man to come face to face with a glaring sin in his life, which is covetousness, showing that the young man is neither "good", nor has "kept all (the Commandments) from his youth up":
Matthew 19:21
21 Jesus said unto him, If thou wilt be perfect, go and sell that thou hast, and give to the poor, and thou shalt have treasure in heaven: and come and follow me.
Mark 10:21
21 Then Jesus beholding him loved him, and said unto him, One thing thou lackest: go thy way, sell whatsoever thou hast, and give to the poor, and thou shalt have treasure in heaven: and come, take up the cross, and follow me.
Mark 10:21
22 Now when Jesus heard these things, he said unto him, Yet lackest thou one thing: sell all that thou hast, and distribute unto the poor, and thou shalt have treasure in heaven: and come, follow me.
This again is Jesus "using the Law" on the young man, as He pulls the First Commandment (Exodus 20:3) on him - covetousness is tantamount to idolatry (Colossians 3:5, Ephesians 5:5), and therefore breaks the First Commandment.
The young man's loved his wealth, and leaves Christ, sorrowful because he was very rich (Matthew 19:22, Mark 10:22, Luke 18:23). As the young man departs, he gives no indication that he ever understood what Christ was trying to show him - his heart was too hard, and he was too self-righteous to allow the Law to convict him.
Then, the famous passage from Christ:
Matthew 19:23-24
23 Then said Jesus unto his disciples, Verily I say unto you, That a rich man shall hardly enter into the kingdom of heaven.
24 And again I say unto you, It is easier for a camel to go through the eye of a needle, than for a rich man to enter into the kingdom of God.
25 When his disciples heard it, they were exceedingly amazed, saying, Who then can be saved?
Also, from the account in Mark, we see more specifically the exact reason that the riches damn you:
Mark 10:24
24 And the disciples were astonished at his words. But Jesus answereth again, and saith unto them, Children, how hard is it for them that trust in riches to enter into the kingdom of God!
The man's problem was misplaced trust. That's the problem of every unsaved person on the planet. They are trusting in something that cannot save them, whether it be their good life, their Law keeping, etc. - none of those things will work, because they are intimately tied to human effort, and are therefore imperfect (Galatians 3:11, James 2:10).
This is why Christ concludes the lesson with:
Luke 18:27
27 And he said, The things which are impossible with men are possible with God.
What's impossible for men? Salvation. Getting Eternal life. The whole purpose of the passage is to show you that, so that you see your need for Christ's blood atonement for sin, so that you can be seen as truly "Good" in the eyes of God.
This is why Christ elsewhere answered a similar query by making it clear that the only "work" you can do to make it to Heaven is actually a non-work - it's ceasing from work altogether, and instead putting your faith in another's work:
John 6:28-29
28 Then said they unto him, What shall we do, that we might work the works of God?
29 Jesus answered and said unto them, This is the work of God, that ye believe on him whom he hath sent.
God makes this clear to us in yet another passage, where a man - a jailor this time, asks basically the same thing as the rich young ruler:
Acts 16:30-31
30 And brought them out, and said, Sirs, what must I do to be saved?
31 And they said, Believe on the Lord Jesus Christ, and thou shalt be saved, and thy house.
This synthesizes exactly what Jesus said in His response to the young man. It's a clear statement, which is naturally why it's ignored by 100% of Roman Catholic priests and in favor of the passages from the Gospels, which are more easily twisted to their own destruction (2 Peter 3:16).
Ironically, the people using this passage to teach Lordship or works Salvation are the rich young ruler. They've made the exact same mistake that he did.
This passage is meant to show you your need for a Savior by confronting you with the demands of the Law. The point is not to encourage you to follow Christ (work), keep the Law (work), and sell what you have (work) for Salvation. Those instructions are given to the man as discipleship instructions while entertaining the young man's delusion that he has kept the Law satisfactorily.
If these were conditions for Salvation, it would be impossible. Hence the conclusion, "with men this is impossible". Of course, obeying Christ's discipleship commands are not automatic (hence why the commandment is there in the first place), meaning that they take work. Since Salvation is not of works (Ephesians 2:8-9), this is not the Gospel, and woe to anyone thinking that this is how they can get to Heaven.
You have no chance of meeting this standard if that's your hope (Galatians 2:16). The only way to make this possible is by obtaining the righteousness of the only one who ever did meet this standard, God Almighty:
Philippians 3:9
9 And be found in him, not having mine own righteousness, which is of the law, but that which is through the faith of Christ, the righteousness which is of God by faith: