Making Linux work-using tips

Source: Internet
Author: User
Tags virtual environment

Making Linux work-using tips 1 overview

In a beginner's eyes, the Linux CLI interface is not as colorful and friendly as the graphical interface, but as a slightly advanced Linux player, it will naturally accumulate a lot of experience and skills to make Linux more and more usable, more and more comfortable, even issued " Get rid of the constraints of the graphical interface, the whole people are more free "feeling.

Of course, what we say is getting more and more useful, is in a limited area:

    • Network requests
    • File switching
    • Command execution
    • Program Development

If you are not a developer, this article may not be suitable for you to read.

2 Setting environment variables

Environment variables, the name Incredibles, is to set some and environment for the current operating system environment variables, from the system executes the command when the unified value call.

In the Linux system, there are many ways to design environment variables, which appear in different use situations.

2.1 etc Directory

For example, files in the/etc directory

    • /etc/profile
    • /etc/environment

The settings in this directory are set for all users of this computer, and when the user logs in, the environment variables are loaded first, and if the user directory (as mentioned below) also has environment variable settings, the settings of the user directory will be overwritten.

In general, in order to ensure that the user set up the environment between non-interference, it is recommended to try to set the environment variables under the user directory.

2.2 User Directory

Below the user directory, the main and environment variable settings related files are:

    • . profile file

      Loaded when the user logs on, and only once when the logon event is logged

    • . BASH_RC

      Runs once every time the bash shell is started

In order to ensure the independence of the user configuration data, in general, the environment will be set in the user directory of the . profile file.

For example, write the following to the . profile File:

W= $HOME/work/workspaceexport droot= $HOME/dev-toolsexport p= $HOME/pyvenv/bin

Then make this environment variable effective by selecting one of the following methods:

    1. Log off, and then sign back in. A. profile file is executed at this time.
    2. Execute source. Profile directly in the terminal.

The frequently used high-frequency catalogs are added to the environment variables as above, and then the working directory can be quickly switched to the terminal where the environment variable is applied.

For example, if I want to quickly switch to the working directory, before setting the environment variable, you need to do the following:

Cd/home/harmo/work/workspace

After setting the environment variable:

CD $W

Feel a lot easier in a moment, do not have to remember so long a list of directories.

As a python developer, the usual working directory is:

    • Code Storage Directory
    • Developing the IDE Directory
    • Python Virtual Environment Directory

As previously set, you can save a lot of unnecessary actions.

3 Setting up local domain name resolution

In the Linux file system, there is a file:

    • /etc/hosts

This file belongs to the local static Domain name Mapping table, that is, when a domain name is accessed in a Linux system, it takes precedence over the parsing of this file, and then references the downstream DNS server node.

 (pyvenv)? ~ cat /etc/hosts### Host database## localhost is  Used to configure the loopback interface#, the system is booting. Do not change the this entry.##  127.0 . 0.1   localhost  255.255 . 255.255   Broadcasthost::  1   localhost  119.14 . 121.48   Web_server  119.14 . 121.42   Database_server  119.14 . 121.40  nginx_server 

For a developer who often wants to deal with a variety of servers, it is not necessary to spend the brainpower to remember the IP of the various servers, but to tag the IP with an easy-to-remember name, that is, the function of DNS.

For example, if you want to telnet to a Web server, you need to execute the following command before you set up the hosts:

SSH [Email protected] 119.14. 121.48

After the above setup, you only need to do the following:

SSH [Email Protected]_server

Perhaps the login of a server does not show this way of artifice , but as long as the number of servers increased, such as to 10, memory 10 machine name should be more than the memory of 10 digital IP is much easier, because you tagged alias will cause your Lenovo, but IP will not.

4 Using Ssh-key Authentication

When it comes to SSH, it's no stranger to developers in a Linux environment. In general, the most frequently used is from the following two scenarios:

    • Remote server logon operation identity authentication
    • Git Code Server identity authentication

Both of these scenarios require authentication , and the traditional approach is to enter the password directly, the disadvantage of which is:

    • Cumbersome input process
    • Requires user memory password
    • Password may be intercepted

The use of Ssh-key uses a set of cryptographic strings from a public/private key to authenticate.

The build method is as follows:

(pyvenv)?  Ssh-keygen -C [email protected]generatingpublic/fileinwhich To save the key (/home/harmo/.  SSH/id_rsa):

Following the wizard to complete the subsequent settings, a set of files is generated natively:

-RW-------  1 harmo  staff   1. 6K  1: id_rsa-rw-------  1 harmo  staff   401B  116 : id_rsa.pub

which

    • Id_rsa private Key
    • Id_rsa.pub Public Key

This set of files is stored directly on the local computer, as long as the public key information is copied to the appropriate server, set to trust the public key.

In the subsequent process, the authentication between the client and the server is automatically authenticated by Ssh-key, no longer requires user input or even memory password.

While there are some other technical solutions for password-free input, such as:

    • Sshpass
    • . netrc

However, their disadvantage is that they still need to keep the account and password plaintext in this machine. This poses a danger: As long as the machine is hack, these plaintext will be lost, and the impact is far more serious than the loss of Ssh-key.

5 Summary

About Linux, the above may be some artifice, but admittedly, after mastering these small skills, it is really able to make the system handy, more and more experience the beauty of Linux.

Author: Harmo ha mo
Author Introduction: Https://zhengwh.github.io
Technical Blog: Http://www.cnblogs.com/beer
Email: [Email protected]
Qq: 1295351490
Time: 2016-02
Copyright Notice: Welcome to learn to exchange for the purpose of the reader to reprint, but please "annotated source"
Support this article: If you are inspired by the article, you can click the button in the lower right corner of the blog to "recommend"

Making Linux work-using tips

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.