Linux Login auto-switch root account and History command optimization

Source: Internet
Author: User
Tags ssh server

1 : When we Linux system optimization is done using Oldboy users connect to the CRT remotely login, each connection requires sudo Su- or Su- Enter password to log in, how can I get in CRT automatically switch to root when connected account, (Hint: CRT The connected user is Oldboy , so only for Oldboy with this feature)

Application Scenario: When we use Oldboy users to remotely connect to the system, we always need to switch to the root account with sudo or su, which greatly affects our productivity, we can modify the Oldboy user home directory. Bash_ Profile configuration file so that it runs the command automatically at logon.

Answer:

Method 1: Achieve this effect by modifying the. Bash_profile user environment variable profile in the Oldboy user home directory

To set up a connection to the SSH server automatically run sudo su-command method, you can modify the Oldboy local variable file

[[email protected] ~]# Vi/home/oldboy/.bash_profileßvi Edit

[[email protected] ~]# echo "sudo su-" >>/home/oldboy/.bash_profileßecho append

sudo su-

Recommendation: You can add the above configuration to the Linux optimizer so that we do not manually switch to the root account every time we use Oldboy login! (Learning environment only)

When we re-use the Oldboy user login, we will find that the system will automatically switch to the root account, so you can save a lot of tedious steps.

. Bash.profile detailed configuration file:

. Bash_profile is the most important file that is read every time a user logs on to the system and contains commands that are executed by bash.

This file defines the basic environment of the user login account: including path and some alias alias settings.

If you change the contents of your. bash_profile file, the change will not take effect until you exit and log on again after the file is read again. If you are impatient, use source. Bash_profile to have its changes take effect immediately.

Tip: the. bash_profile file is read and executed only by the login shell, that is, if your initial shell is Cshell. Then when you perform a bash switch to the bash environment, the. Bash_profile is not read. The. bashrc file is read at this time

2 : How do I make the user root every time we log in Previous command history is cleared to prevent hackers from logging in to view root command history for your account!

Application Scenario: Although we only record 5 lines of command in Linux optimization, but this for our production environment still affect efficiency, sometimes do some operations need to call Historical command directly, improve work efficiency, but found that the history of the command only 5, which greatly affected our efficiency. So we just need to automatically clear the history command every time we log in with the login system.

First Linux optimizations are only logged when the configuration of the 5 command history is canceled

Answer:

Method 1: This method can replace the Linux History command optimization to achieve a very safe level

[Email protected] ~]# Vi. bash_profile

[Email protected] ~]# echo-e "history-c \ r > bash_history" >>/root/.bash_profile

History-c

>. bash_history

Recommendation: You can add the above configuration to the Linux optimizer so that we don't worry about command history being viewed by others! (Learning environment only)

Method 2: You can also write to the. Bash_logout configuration file

Questions about command history: You can use the Log Auditing feature to collect system command history specifically to address the needs of some children's shoes

Linux Login auto-switch root account and History command optimization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.