When you are running MATLAB from the command line (any SSH client), you can use 'nodesktop' mode to run MATLAB command line mode. Use the following command to run MATLAB from terminal:
>> matlab -nodesktop -nosplash
There is no need to alter 'opengl' behavior until you are trying to launch some figures. You can disable launching figure windows by specifying the '' startup option. For example,
>> matlab -nodesktop -nosplash -noFigureWindows
Also, if you want to alter opengl behavior or want to execute any script while launching MATLAB, you can use the '-r' flag and execute the script. For example,
>> matlab -r "opengl software"
Refer to the following documentation link for more startup options: