Very short version
– (optional) When you submit your article to a journal, upload that pre-print non-peer-reviewd version in a pre-print repository of your choice (e.g. Zenodo, MarXiv, …) with a CC-BY licence.
– When your article has been accepted, upload that post-print peer-reviwed version in MarXiv (with the licence required by the publisher; e.g. it could be a CC-BY-NC-ND licence)
– Wait that the final paper is published in your selected journal.