The pandemic caused by Covid-19 is still present around the world. Despite advances in combating the disease, such as vaccine development, identifying infected individuals is still essential to optimize the control of human-to-human transmission of the virus. The main technique for detecting the virus is the RT-PCR method, which, despite its high relative cost, has a high accuracy in detecting the coronavirus. Given this, a method capable of performing the identification quickly, accurately, and inexpensively is necessary. Thus, this work aimed to analyze the feasibility of a new technique for identifying SARS-CoV-2 through the use of optical spectroscopy in the visible and near-infrared range (Vis–NIR) combined with machine learning algorithms. Spectral signals were obtained from nasopharyngeal swab samples previously analyzed using the RT-PCR method. The specimens were provided by the Molecular Diagnosis Laboratory of Covid-19 at Univasf. A total of 314 samples were analyzed, comprising 42 testing positive and 272 testing negative for Covid-19. Digital signal processing techniques, such as Savitzky–Golay filters and statistical methods were used to eliminate spurious elements from the original data and extract relevant features. Supervised machine learning algorithms such as SVM, Random Forest, and Naive Bayes classifiers were used to perform automatic sample identification. To evaluate the performance of the models, a 5-fold cross-validation technique was applied. With the proposed methodology, it was possible to achieve an accuracy of 75%, a sensitivity of 80%, and a specificity of 70%, in addition to an area under the ROC curve of 0.81, in the identification of nasopharyngeal swab samples from previously diagnosed individuals. From these results, it was possible to conclude that Vis–NIR spectroscopy is a promising, fast and relatively low cost technique to identify the SARS-CoV-2.