1Jn 2:4 Whoever says “I know him” but does not keep his commandments is a liar, and the truth is not in him,
1Jn 2:5 but whoever keeps his word, in him truly the love of God is perfected. By this we may know that we are in him:
1Jn 2:6 whoever says he abides in him
ought to walk in the same way in which he walked.
1Jn 2:7 Beloved, I am writing you no new commandment, but
an old commandment that you had from the beginning.
The old commandment is the word that you have heard.
1Jn 2:8 At the same time,
it is a new commandment that I am writing to you, which is true in him and in you, because the darkness is passing away and the true light is already shining.
1Jn 3:22 and whatever we ask we receive from him,
because we keep his commandments and do what pleases him.
1Jn 3:23 And
this is his commandment, that we believe in the name of his Son Jesus Christ and love one another,
just as he has commanded us.
1Jn 3:24 Whoever keeps his commandments abides in God, and God in him. And by this we know that he abides in us, by the Spirit whom he has given us.
1Jn 4:21 And this commandment we have from him: whoever loves God must also love his brother.
1Jn 5:2 By this we know that we love the children of God, when we love God and obey his commandments.
1Jn 5:3 For this is the love of God, that we keep his commandments. And his commandments are not burdensome.
(All ESV.)
Not only does Jesus himself give his followers commandments to follow, he says that "If you love me, you will keep my commandments. . . . Whoever has my commandments and keeps them, he it is who loves me. And he who loves me will be loved by my Father." In other words, a person cannot claim to love Jesus and be his friend but not follow his commandments. And if they don't love Jesus, as seen in keeping his commandments, then the Father won't love them.
That is why John says that 'Whoever says “I know him” but does not keep his commandments is a liar, and the truth is not in him," and that "Whoever keeps his commandments abides in God, and God in him." In these passages, John is simply reiterating Jesus's words--God only abides in those who love him and whose love is shown by keeping his commandments.
Anyone who says or lives otherwise, doesn't actually love Jesus and so "is a liar, and the truth is not in him." That's according to Jesus's and John's words, not mine.