【背景】
折腾:
【未解决】Dovecot启动出错:dovecot Fatal Couldn’t parse private ssl_key Expecting ANY PRIVATE KEY
期间,需要去在CentOS 7中切换用户,到root,去执行对应的命令:
/usr/share/doc/dovecot-2.2.10/mkcert.sh
【折腾过程】
1.搜:
linux 切换用户
centos 7 切换用户
centos 7 switch user
参考:
ubuntu linux切换用户到root – 学习记录 – 博客频道 – CSDN.NET
Linux系统中切换用户身份su与sudo的用法与实例 – 斑马Linux – 51CTO技术博客
su – xxx
==su -l xxx
不指定用户,默认为root,所以:
su -
== su -l
== su -l root
去试试:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | crifan@crifan:~$ ll /usr/share/doc/dovecot-2 .2.10/ -rw-r--r-- 1 root root 931 Jun 26 2014 mkcert.sh crifan@crifan:~$ sudo /usr/share/doc/dovecot-2 .2.10 /mkcert .sh sudo : /usr/share/doc/dovecot-2 .2.10 /mkcert .sh: command not found crifan@crifan:~$ /usr/share/doc/dovecot-2 .2.10 /mkcert .sh - bash : /usr/share/doc/dovecot-2 .2.10 /mkcert .sh: Permission denied crifan@crifan:~$ su - Password: Last login: Sat Aug 15 14:53:40 CST 2015 on pts /1 Last failed login: Sat Aug 15 14:56:40 CST 2015 from 222.186.21.234 on ssh :notty There were 22 failed login attempts since the last successful login. [root@crifan ~] # chmod u+x //usr/share/doc/dovecot-2.2.10/mkcert.sh [root@crifan ~] # ll //usr/share/doc/dovecot-2.2.10/mkcert.sh -rwxr--r-- 1 root root 931 Jun 26 2014 //usr/share/doc/dovecot-2 .2.10 /mkcert .sh [root@crifan ~] # ll /usr/share/doc/dovecot-2.2.10/mkcert.sh -rwxr--r-- 1 root root 931 Jun 26 2014 /usr/share/doc/dovecot-2 .2.10 /mkcert .sh [root@crifan ~] # /usr/share/doc/dovecot-2.2.10/mkcert.sh Generating a 1024 bit RSA private key .........................++++++ ........++++++ writing new private key to '/etc/pki/dovecot/private/dovecot.pem' ----- subject= /OU =IMAP server /CN =imap.example.com /emailAddress =postmaster@example.com SHA1 Fingerprint=A9:6C:7D:87:90:2F:5A:3C:F3:7A:EB:3D:A8:D4:EE:C6:FD:88:39:39 [root@crifan ~] # su -l crifan Last login: Sat Aug 15 14:56:32 CST 2015 on pts /1 crifan@crifan:~$ |
2.另外再去试试:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | crifan@crifan:~$ su Password: [root@crifan crifan] # pwd /home/crifan [root@crifan crifan] # su -l crifan Last login: Sat Aug 15 14:58:05 CST 2015 on pts /1 crifan@crifan:~$ su -l Password: Last login: Sat Aug 15 15:01:21 CST 2015 on pts /1 [root@crifan ~] # su -l crifan Last login: Sat Aug 15 15:01:32 CST 2015 on pts /1 crifan@crifan:~$ su -l root Password: Last login: Sat Aug 15 15:01:42 CST 2015 on pts /1 Last failed login: Sat Aug 15 15:02:01 CST 2015 from 222.186.21.234 on ssh :notty There were 2 failed login attempts since the last successful login. [root@crifan ~] # su -l crifan Last login: Sat Aug 15 15:01:53 CST 2015 on pts /1 crifan@crifan:~$ su - Password: Last login: Sat Aug 15 15:02:02 CST 2015 on pts /1 Last failed login: Sat Aug 15 15:02:03 CST 2015 from 222.186.21.234 on ssh :notty There was 1 failed login attempt since the last successful login. [root@crifan ~] # su -l crifan Last login: Sat Aug 15 15:02:12 CST 2015 on pts /1 |
如图:
【总结】
从普通用户切换到root,算有三种:
- su
- 用su登录root后,不知道为何提示符变成了:
- [root@crifan crifan]#
- 多了个 crifan,觉得很奇怪,不懂。
- su –
- su -和su -l root好像是一样的。
- su -l root
- 推荐用此种,最完整的写法:su -l root
从root切换到普通用户:
su -l normal_username
比如:
1 2 | [root@crifan ~] # su -l crifan Last login: Sat Aug 15 15:01:32 CST 2015 on pts /1 |
转载请注明:在路上 » 【已解决】Linux的CentOS 7系统中如何切换用户