Unable to connect oracle 12 database remotely while local connection works
Env:

[root@o71 ~]# tail -5 /home/oracle/.bash_profile

export ORACLE_SID=MIN18
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/18.0.0/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH


Local:

[root@o71 ~]# su - oracle -c "sqlplus / as sysdba"

SQL*Plus: Release 18.0.0.0.0 - Production on Tue Jan 15 15:54:16 2019
Version 18.4.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.


Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0

SQL&gt;


Remote:

[root@o72 ~]# ssh root@o71 su - oracle -c "sqlplus / as sysdba "

SQL*Plus: Release 18.0.0.0.0 - Production on Tue Jan 15 15:55:15 2019
Version 18.4.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.

Enter user-name:


Remote with better syntax:

[root@o72 ~]# ssh root@o71 'su - oracle -c "sqlplus / as sysdba "'

SQL*Plus: Release 18.0.0.0.0 - Production on Tue Jan 15 15:55:39 2019
Version 18.4.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.


Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0

SQL&gt;


Instead of:

ssh root@node2 su - oraabc -c "/oracle/ABC/12102/bin/sqlplus / as sysdba"


Use this:

ssh root@node2 'su - oraabc -c "/oracle/ABC/12102/bin/sqlplus / as sysdba"'


Also I find it really bad practice to set these variables in profile by default. Just use oraenv.

Example:

[root@o72 ~]# ssh root@o71 'su - oracle -c "export ORAENV_ASK=NO; export ORACLE_SID=MIN18; . oraenv; sqlplus / as sysdba "'
The Oracle base remains unchanged with value /u01/app/oracle

SQL*Plus: Release 18.0.0.0.0 - Production on Tue Jan 15 15:56:51 2019
Version 18.4.0.0.0

Copyright (c) 1982, 2018, Oracle.  All rights reserved.


Connected to:
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production
Version 18.4.0.0.0

SQL&gt;