Beam matching is a common technique that is routinely employed in accelerator design with the aim of minimizing beam losses and preservation of beam brightness. Despite being widely used, a full theoretical understanding of beam matching in 6D remains elusive. Here, we present an analytical treatment of 6D beam matching of a high-intensity beam onto an RF structure. We begin our analysis within the framework of a linear model, and apply the averaging method to a set of 3D beam envelope equations. Accordingly, we obtain a matched solution that is comprised of smoothed envelopes and periodic terms, describing envelope oscillations with the period of the focusing structure. We then consider the nonlinear regime, where the beam size is comparable with the separatrix size. Stating with a Hamiltonian analysis in 6D phase space, we attain a selfconsistent beam profile and show that it is significantly different from the commonly used ellipsoidal shape. Subsequently, we analyze the special case of an equilibrium with equal space charge depression between all degrees of freedom. Comparison of beam dynamics for equipartitioned, equal space charge depression, and equal emittances beams is given. Finally, we present experimental results on beam matching in the LANSCE linac.