There is no explicit requirement for a public confession or baptism, nor is there any prohibition of doing it in secret.
Timothy’s “confession” (usually meaning the baptism and its proclamation) is described in 1 Timothy 6:
Fight the good fight of the faith. Take hold of the eternal life to which you were called and about which you made the good confession in the presence of many witnesses. (1Ti 6:12)
So Timothy’s confession was public, in the presence of many witnesses. Making such a public proclamation is pragmatically a good idea — it serves as a witness to Jesus, and strengthens your faith. But it’s not required.
On the other hand, Jesus has something to say about hiding your beliefs:
So everyone who acknowledges me before men, I also will acknowledge before my Father who is in heaven, but whoever denies me before men, I also will deny before my Father who is in heaven. (Matt 10 : 32 – 33 )
But once you are baptized, your life is in God’s hands, and Jesus will look after you, whether the secret comes out or not. And there are no secrets that will not eventually be manifest:
For nothing is hidden that will not be made manifest, nor is anything secret that will not be known and come to light. (Luke 8:17)