Linux操作系统用户以同名数据库用户身份免密码登录Oracle11g数据库

Linux操作系统用户以同名数据库用户身份免密码登录Oracle11g数据库
 

注: os_authent_prefix是Oracle用来验证用户尝试连接到server时指定的一个前缀。oracle把该参数的值和操作系统账户名和密码连接起来。当需要连接的时候,Oracle 把带有前缀的操作系统用户名和数据库中Oracle的用户名进行比较。其缺省值为 'ops$',当数据库中存在用户 ops$test。那么在操作系统上以 test 用户登录成功后,键入sqlplus / ,登录用户将是 ops$tes。也可将该参数设为空,这样可以消除给操作系统的账户添加任何的前缀。

 
操作流程说明
第一步,配置数据库,更新 os_authent_prefix  参数的值为空(默认ops$)
第二步,建立 数据库用户 appviewdb 并授予连接数据库权限
第三步,建立linux操作系统用户 appviewdb 并配置相关环境变量,以便其能使用sqlplus命令连接数据库
第四步,测试操作系统用户 appviewdb连接数据的情况
 
1.数据库参数相关配置,并重启数据库让配置生效
1.1 更新数据库 os_authent_prefix参数值为空(默认ops$)
[oracle@fanxin01 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sun Apr 26 19:39:11 2020
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
 
SQL> show parameter os_au;
NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
os_authent_prefix             string     ops$
remote_os_authent             boolean     FALSE
SQL>
SQL> alter system set os_authent_prefix="" scope=spfile;
alter system set os_authent_prefix="" scope=spfile
                                   *
ERROR at line 1:
ORA-01741: illegal zero-length identifier
SQL> alter system set os_authent_prefix='' scope=spfile;
System altered.
SQL> show parameter os_au;
NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
os_authent_prefix             string     ops$
remote_os_authent             boolean     FALSE
 
 
1.2重启数据库让配置生效
###重启数据库
[oracle@fanxin01 ~]$ srvctl stop database -d FXDB
[oracle@fanxin01 ~]$ srvctl status database -d FXDB
实例 fxdb1 没有在 fanxin01 节点上运行
实例 fxdb2 没有在 fanxin02 节点上运行
[oracle@fanxin01 ~]$ srvctl start database -d FXDB
[oracle@fanxin01 ~]$ srvctl status database -d FXDB
实例 fxdb1 正在节点 fanxin01 上运行
实例 fxdb2 正在节点 fanxin02 上运行
 
[oracle@fanxin01 ~]$ sqlplus / as sysdba
SQL> show parameter os_au;
NAME                     TYPE     VALUE
------------------------------------ ----------- ------------------------------
os_authent_prefix             string
remote_os_authent             boolean     FALSE
 
2.创建数据库用户 appviewdb 并授予连接数据库的权限
SQL> create user appviewdb identified externally;
User created.
 
SQL> grant connect,resource to appviewdb;
Grant succeeded.
 
SQL> grant select on scott.emp to appviewdb;
Grant succeeded.
 
SQL> set linesize 200;
SQL> select * from scott.emp where rownum<2;
     EMPNO ENAME      JOB           MGR HIREDATE        SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7788 SCOTT      ANALYST          7566 19-APR-87       3000            20
 
3.创建操作系统用户 appviewdb 并配置好环境变量
3.1 创建操作系统用户 appviewdb
[root@fanxin01 ~]# useradd appviewdb
[root@fanxin01 ~]# passwd appviewdb
更改用户 appviewdb 的密码 。
新的 密码:
无效的密码: 它基于字典单词
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
 
3.2 配置操作系统用户 appviewdb 的环境变量,以使其能使用 sqlplus 命令连接数据库
[root@fanxin01 ~]# cat /home/oracle/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
 
 
# User specific environment and startup programs
 
 
PATH=$PATH:$HOME/bin
export PATH
export ORACLE_SID=fxdb1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
stty erase ^h
 
 
[root@fanxin01 ~]# su - appviewdb
[appviewdb@fanxin01 ~]$ cat ~/.bash_profile
# .bash_profile
 
 
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi
 
 
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export ORACLE_SID=fxdb1
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0.4/db_1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
stty erase ^h
export PATH
 
4.测试操作系统用户 appviewdb 连接数据库情况
[appviewdb@fanxin01 ~]$ sqlplus /
 
SQL*Plus: Release 11.2.0.4.0 Production on Sun Apr 26 20:24:05 2020
 
Copyright (c) 1982, 2013, Oracle.  All rights reserved.
 
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
 
 
SQL> show user;
USER is "APPVIEWDB"
 
SQL> set linesize 200;
SQL> select * from scott.emp where rownum < 3;
 
 
     EMPNO ENAME      JOB           MGR HIREDATE        SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7788 SCOTT      ANALYST          7566 19-APR-87       3000            20
      7369 SMITH      CLERK          7902 17-DEC-80        800            20
 
 
至此,操作完毕,达到预期效果~!~
发布了10 篇原创文章 · 获赞 3 · 访问量 1401

猜你喜欢

转载自blog.csdn.net/tttt0611/article/details/105776725