Ctrl+X. If you dont have unsaved changes, this will exit nano immediately.
In case you have unsaved changes, it will ask you whether to save those changes after pressing.
Yto tell it to save the changes you’ve made. It will then ask you to check or enter the filename to save to. Once you are finished with the filename, press Enter.
Nto discard all changes (you won’t be able to restore your changes later) and exit nano immediately.