The spatial distribution of the stress tensor around the quark--anti-quark ($Qbar{Q}$) pair in SU(3) lattice gauge theory is studied. The Yang-Mills gradient flow plays a crucial role to make the stress tensor well-defined and derivable from the numerical simulations on the lattice. The resultant stress tensor with a decomposition into local principal axes shows, for the first time, the detailed structure of the flux tube along the longitudinal and transverse directions in a gauge invariant manner. The linear confining behavior of the $Qbar{Q}$ potential at long distances is derived directly from the integral of the local stress tensor.