Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
wxy 2018-01-28 20:39:14 +08:00
commit 7439d7f9fb
21 changed files with 1767 additions and 794 deletions

View File

@ -1,3 +1,4 @@
Translating by Wuod3n
Deep learning wars: Facebook-backed PyTorch vs Google's TensorFlow
======
The rapid rise of tools and techniques in Artificial Intelligence and Machine learning of late has been astounding. Deep Learning, or "Machine learning on steroids" as some say, is one area where data scientists and machine learning experts are spoilt for choice in terms of the libraries and frameworks available. A lot of these frameworks are Python-based, as Python is a more general-purpose and a relatively easier language to work with. [Theano][1], [Keras][2] [TensorFlow][3] are a few of the popular deep learning libraries built on Python, developed with an aim to make the life of machine learning experts easier.

View File

@ -0,0 +1,87 @@
Security Chaos Engineering: A new paradigm for cybersecurity
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/life_bank_vault_secure_safe.png?itok=YoW93h7C)
Security is always changing and failure always exists.
This toxic scenario requires a fresh perspective on how we think about operational security. We must understand that we are often the primary cause of our own security flaws. The industry typically looks at cybersecurity and failure in isolation or as separate matters. We believe that our lack of insight and operational intelligence into our own security control failures is one of the most common causes of security incidents and, subsequently, data breaches.
> Fall seven times, stand up eight." --Japanese proverb
The simple fact is that "to err is human," and humans derive their success as a direct result of the failures they encounter. Their rate of failure, how they fail, and their ability to understand that they failed in the first place are important building blocks to success. Our ability to learn through failure is inherent in the systems we build, the way we operate them, and the security we use to protect them. Yet there has been a lack of focus when it comes to how we approach preventative security measures, and the spotlight has trended toward the evolving attack landscape and the need to buy or build new solutions.
### Security spending is continually rising and so are security incidents
We spend billions on new information security technologies, however, we rarely take a proactive look at whether those security investments perform as expected. This has resulted in a continual increase in security spending on new solutions to keep up with the evolving attacks.
Despite spending more on security, data breaches are continuously getting bigger and more frequent across all industries. We have marched so fast down this path of the "get-ahead-of-the-attacker" strategy that we haven't considered that we may be a primary cause of our own demise. How is it that we are building more and more security measures, but the problem seems to be getting worse? Furthermore, many of the notable data breaches over the past year were not the result of an advanced nation-state or spy-vs.-spy malicious advanced persistent threats (APTs); rather the principal causes of those events were incomplete implementation, misconfiguration, design flaws, and lack of oversight.
The 2017 Ponemon Cost of a Data Breach Study breaks down the [root causes of data breaches][1] into three areas: malicious or criminal attacks, human factors or errors, and system glitches, including both IT and business-process failure. Of the three categories, malicious or criminal attacks comprises the largest distribution (47%), followed by human error (28%), and system glitches (25%). Cybersecurity vendors have historically focused on malicious root causes of data breaches, as it is the largest sole cause, but together human error and system glitches total 53%, a larger share of the overall problem.
What is not often understood, whether due to lack of insight, reporting, or analysis, is that malicious or criminal attacks are often successful due to human error and system glitches. Both human error and system glitches are, at their root, primary markers of the existence of failure. Whether it's IT system failures, failures in process, or failures resulting from humans, it begs the question: "Should we be focusing on finding a method to identify, understand, and address our failures?" After all, it can be an arduous task to predict the next malicious attack, which often requires investment of time to sift threat intelligence, dig through forensic data, or churn threat feeds full of unknown factors and undetermined motives. Failure instrumentation, identification, and remediation are mostly comprised of things that we know, have the ability to test, and can measure.
Failures we can analyze consist not only of IT, business, and general human factors but also the way we design, build, implement, configure, operate, observe, and manage security controls. People are the ones designing, building, monitoring, and managing the security controls we put in place to defend against malicious attackers. How often do we proactively instrument what we designed, built, and are operationally managing to determine if the controls are failing? Most organizations do not discover that their security controls were failing until a security incident results from that failure. The worst time to find out your security investment failed is during a security incident at 3 a.m.
> Security incidents are not detective measures and hope is not a strategy when it comes to operating effective security controls.
We hypothesize that a large portion of data breaches are caused not by sophisticated nation-state actors or hacktivists, but rather simple things rooted in human error and system glitches. Failure in security controls can arise from poor control placement, technical misconfiguration, gaps in coverage, inadequate testing practices, human error, and numerous other things.
### The journey into Security Chaos Testing
Our venture into this new territory of Security Chaos Testing has shifted our thinking about the root cause of many of our notable security incidents and data breaches.
We were brought together by [Bruce Wong][2], who now works at Stitch Fix with Charles, one of the authors of this article. Prior to Stitch Fix, Bruce was a founder of the Chaos Engineering and System Reliability Engineering (SRE) practices at Netflix, the company commonly credited with establishing the field. Bruce learned about this article's other author, Aaron, through the open source [ChaoSlingr][3] Security Chaos Testing tool project, on which Aaron was a contributor. Aaron was interested in Bruce's perspective on the idea of applying Chaos Engineering to cybersecurity, which led Bruce to connect us to share what we had been working on. As security practitioners, we were both intrigued by the idea of Chaos Engineering and had each begun thinking about how this new method of instrumentation might have a role in cybersecurity.
Within a short timeframe, we began finishing each other's thoughts around testing and validating security capabilities, which we collectively call "Security Chaos Engineering." We directly challenged many of the concepts we had come to depend on in our careers, such as compensating security controls, defense-in-depth, and how to design preventative security. Quickly we realized that we needed to challenge the status quo "set-it-and-forget-it" model and instead execute on continuous instrumentation and validation of security capabilities.
Businesses often don't fully understand whether their security capabilities and controls are operating as expected until they are not. We had both struggled throughout our careers to provide measurements on security controls that go beyond simple uptime metrics. Our journey has shown us there is a need for a more pragmatic approach that emphasizes proactive instrumentation and experimentation over blind faith.
### Defining new terms
In the security industry, we have a habit of not explaining terms and assuming we are speaking the same language. To correct that, here are a few key terms in this new approach:
* **(Security) Chaos Experiments** are foundationally rooted in the scientific method, in that they seek not to validate what is already known to be true or already known to be false, rather they are focused on deriving new insights about the current state.
* **Security Chaos Engineering** is the discipline of instrumentation, identification, and remediation of failure within security controls through proactive experimentation to build confidence in the system's ability to defend against malicious conditions in production.
### Security and distributed systems
Consider the evolving nature of modern application design where systems are becoming more and more distributed, ephemeral, and immutable in how they operate. In this shifting paradigm, it is becoming difficult to comprehend the operational state and health of our systems' security. Moreover, how are we ensuring that it remains effective and vigilant as the surrounding environment is changing its parameters, components, and methodologies?
What does it mean to be effective in terms of security controls? After all, a single security capability could easily be implemented in a wide variety of diverse scenarios in which failure may arise from many possible sources. For example, a standard firewall technology may be implemented, placed, managed, and configured differently depending on complexities in the business, web, and data logic.
It is imperative that we not operate our business products and services on the assumption that something works. We must constantly, consistently, and proactively instrument our security controls to ensure they cut the mustard when it matters. This is why Security Chaos Testing is so important. What Security Chaos Engineering does is it provides a methodology for the experimentation of the security of distributed systems in order to build confidence in the ability to withstand malicious conditions.
In Security Chaos Engineering:
* Security capabilities must be end-to-end instrumented.
* Security must be continuously instrumented to build confidence in the system's ability to withstand malicious conditions.
* Readiness of a system's security defenses must be proactively assessed to ensure they are battle-ready and operating as intended.
* The security capability toolchain must be instrumented from end to end to drive new insights into not only the effectiveness of the functionality within the toolchain but also to discover where added value and improvement can be injected.
* Practiced instrumentation seeks to identify, detect, and remediate failures in security controls.
* The focus is on vulnerability and failure identification, not failure management.
* The operational effectiveness of incident management is sharpened.
As Henry Ford said, "Failure is only the opportunity to begin again, this time more intelligently." Security Chaos Engineering and Security Chaos Testing give us that opportunity.
Would you like to learn more? Join the discussion by following [@aaronrinehart][4] and [@charles_nwatu][5] on Twitter.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/1/new-paradigm-cybersecurity
作者:[Aaron Rinehart][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/aaronrinehart
[1]:https://www.ibm.com/security/data-breach
[2]:https://twitter.com/bruce_m_wong?lang=en
[3]:https://github.com/Optum/ChaoSlingr
[4]:https://twitter.com/aaronrinehart
[5]:https://twitter.com/charles_nwatu

View File

@ -1,3 +1,5 @@
Translating by jessie-pang
30 Linux System Monitoring Tools Every SysAdmin Should Know
======

View File

@ -1,297 +0,0 @@
Translating by yyyfor
25 Free Books To Learn Linux For Free
======
Brief: In this article, I'll share with you the best resource to **learn Linux for free**. This is a collection of websites, online video courses and free eBooks.
**How to learn Linux?**
This is perhaps the most commonly asked question in our Facebook group for Linux users.
The answer to this simple looking question 'how to learn Linux' is not at all simple.
Problem is that different people have different meanings of learning Linux.
* If someone has never used Linux, be it command line or desktop version, that person might be just wondering to know more about it.
* If someone uses Windows as the desktop but have to use Linux command line at work, that person might be interested in learning Linux commands.
* If someone has been using Linux for sometimes and is aware of the basics but he/she might want to go to the next level.
* If someone is just interested in getting your way around a specific Linux distribution.
* If someone is trying to improve or learn Bash scripting which is almost synonymous with Linux command line.
* If someone is willing to make a career as a Linux SysAdmin or trying to improve his/her sysadmin skills.
You see, the answer to "how do I learn Linux" depends on what kind of Linux knowledge you are seeking. And for this purpose, I have collected a bunch of resources that you could use for learning Linux.
These free resources include eBooks, video courses, websites etc. And these are divided into sub-categories so that you can easily find what you are looking for when you seek to learn Linux.
Again, there is no **best way to learn Linux**. It totally up to you how you go about learning Linux, by online web portals, downloaded eBooks, video courses or something else.
Let's see how you can learn Linux.
**Disclaimer** : All the books listed here are legal to download. The sources mentioned here are the official sources, as per my knowledge. However, if you find it otherwise, please let me know so that I can take appropriate action.
![Best Free eBooks to learn Linux for Free][1]
## 1. Free materials to learn Linux for absolute beginners
So perhaps you have just heard of Linux from your friends or from a discussion online. You are intrigued about the hype around Linux and you are overwhelmed by the vast information available on the internet but just cannot figure out exactly where to look for to know more about Linux.
Worry not. Most of us, if not all, have been to your stage.
### Introduction to Linux by Linux Foundation [Video Course]
If you have no idea about what is Linux and you want to get started with it, I suggest you to go ahead with the free video course provided by the [Linux Foundation][2] on [edX][3]. Consider it an official course by the organization that 'maintains' Linux. And yes, it is endorsed by [Linus Torvalds][4], the father of Linux himself.
[Introduction To Linux][5]
### Linux Journey [Online Portal]
Not official and perhaps not very popular. But this little website is the perfect place for a no non-sense Linux learning for beginners.
The website is designed beautifully and is well organized based on the topics. It also has interactive quizzes that you can take after reading a section or chapter. My advice, bookmark this website:
[Linux Journey][6]
### Learn Linux in 5 Days [eBook]
This brilliant eBook is available for free exclusively to It's FOSS readers all thanks to [Linux Training Academy][7].
Written for absolute beginners in mind, this free Linux eBook gives you a quick overview of Linux, common Linux commands and other things that you need to learn to get started with Linux.
You can download the book from the page below:
[Learn Linux In 5 Days][8]
### The Ultimate Linux Newbie Guide [eBook]
This is a free to download eBook for Linux beginners. The eBook starts with explaining what is Linux and then go on to provide more practical usage of Linux as a desktop.
You can download the latest version of this eBook from the link below:
[The Ultimate Linux Newbie Guide][9]
## 2. Free Linux eBooks for Beginners to Advanced
This section lists out those Linux eBooks that are 'complete' in nature.
What I mean is that these are like academic textbooks that focus on each and every aspects of Linux, well most of it. You can read those as an absolute beginner or you can read those for deeper understanding as an intermediate Linux user. You can also use them for reference even if you are at expert level.
### Introduction to Linux [eBook]
Introduction to Linux is a free eBook from [The Linux Documentation Project][10] and it is one of the most popular free Linux books out there. Though I think some parts of this book needs to be updated, it is still a very good book to teach you about Linux, its file system, command line, networking and other related stuff.
[Introduction To Linux][11]
### Linux Fundamentals [eBook]
This free eBook by Paul Cobbaut teaches you about Linux history, installation and focuses on the basic Linux commands you should know. You can get the book from the link below:
[Linux Fundamentals][12]
### Advanced Linux Programming [eBook]
As the name suggests, this is for advanced users who are or want to develop software for Linux. It deals with sophisticated features such as multiprocessing, multi-threading, interprocess communication, and interaction with hardware devices.
Following the book will help you develop a faster, reliable and secure program that uses the full capability of a GNU/Linux system.
[Advanced Linux Programming][13]
### Linux From Scratch [eBook]
If you think you know enough about Linux and you are a pro, then why not create your own Linux distribution? Linux From Scratch (LFS) is a project that provides you with step-by-step instructions for building your own custom Linux system, entirely from source code.
Call it DIY Linux but this is a great way to put your Linux expertise to the next level.
There are various sub-parts of this project, you can check it out on its website and download the books from there.
[Linux From Scratch][14]
## 3. Free eBooks to learn Linux command line and Shell scripting
The real power of Linux lies in the command line and if you want to conquer Linux, you must learn Linux command line and Shell scripting.
In fact, if you have to work on Linux terminal on your job, having a good knowledge of Linux command line will actually help you in your tasks and perhaps help you in advancing your career as well (as you'll be more efficient).
In this section, we'll see various Linux commands free eBooks.
### GNU/Linux CommandLine Tools Summary [eBook]
This eBook from The Linux Documentation Project is a good place to begin with Linux command line and get acquainted with Shell scripting.
[GNU/Linux CommandLine Tools Summary][15]
### Bash Reference Manual from GNU [eBook]
This is a free eBook to download from [GNU][16]. As the name suggests, it deals with Bash Shell (if I can call that). This book has over 175 pages and it covers a number of topics around Linux command line in Bash.
You can get it from the link below:
[Bash Reference Manual][17]
### The Linux Command Line [eBook]
This 500+ pages of free eBook by William Shotts is the MUST HAVE for anyone who is serious about learning Linux command line.
Even if you think you know things about Linux, you'll be amazed at how much this book still teaches you.
It covers things from beginners to advanced level. I bet that you'll be a hell lot of better Linux user after reading this book. Download it and keep it with you always.
[The Linux Command Line][18]
### Bash Guide for Beginners [eBook]
If you just want to get started with Bash scripting, this could be a good companion for you. The Linux Documentation Project is behind this eBook again and it's the same author who wrote Introduction to Linux eBook (discussed earlier in this article).
[Bash Guide for Beginners][19]
### Advanced Bash-Scripting Guide [eBook]
If you think you already know basics of Bash scripting and you want to take your skills to the next level, this is what you need. This book has over 900+ pages of various advanced commands and their examples.
[Advanced Bash-Scripting Guide][20]
### The AWK Programming Language [eBook]
Not the prettiest book here but if you really need to go deeper with your scripts, this old-yet-gold book could be helpful.
[The AWK Programming Language][21]
### Linux 101 Hacks [eBook]
This 270 pages eBook from The Geek Stuff teaches you the essentials of Linux command lines with easy to follow practical examples. You can get the book from the link below:
[Linux 101 Hacks][22]
## 4. Distribution specific free learning material
This section deals with material that are dedicated to a certain Linux distribution. What we saw so far was the Linux in general, more focused on file systems, commands and other core stuff.
These books, on the other hand, can be termed as manual or getting started guide for various Linux distributions. So if you are using a certain Linux distribution or planning to use it, you can refer to these resources. And yes, these books are more desktop Linux focused.
I would also like to add that most Linux distributions have their own wiki or documentation section which are often pretty vast. You can always refer to them when you are online.
### Ubuntu Manual
Needless to say that this eBook is for Ubuntu users. It's an independent project that provides Ubuntu manual in the form of free eBook. It is updated for each version of Ubuntu.
The book is rightly called manual because it is basically a composition of step by step instruction and aimed at absolute beginners to Ubuntu. So, you get to know Unity desktop, how to go around it and find applications etc.
It's a must have if you never used Ubuntu Unity because it helps you to figure out how to use Ubuntu for your daily usage.
[Ubuntu Manual][23]
### For Linux Mint: Just Tell Me Damnit! [eBook]
A very basic eBook that focuses on Linux Mint. It shows you how to install Linux Mint in a virtual machine, how to find software, install updates and customize the Linux Mint desktop.
You can download the eBook from the link below:
[Just Tell Me Damnit!][24]
### Solus Linux Manual [eBook]
Caution! This used to be the official manual from Solus Linux but I cannot find its mentioned on Solus Project's website anymore. I don't know if it's outdated or not. But in any case, a little something about Solu Linux won't really hurt, will it?
[Solus Linux User Guide][25]
## 5. Free eBooks for SysAdmin
This section is dedicated to the SysAdmins, the superheroes for developers. I have listed a few free eBooks here for SysAdmin which will surely help anyone who is already a SysAdmin or aspirs to be one. I must add that you should also focus on essential Linux command lines as it will make your job easier.
### The Debian Administration's Handbook [eBook]
If you use Debian Linux for your servers, this is your bible. Book starts with Debian history, installation, package management etc and then moves on to cover topics like [LAMP][26], virtual machines, storage management and other core sysadmin stuff.
[The Debian Administration's Handbook][27]
### Advanced Linux System Administration [eBook]
This is an ideal book if you are preparing for [LPI certification][28]. The book deals straightway to the topics essential for sysadmins. So knowledge of Linux command line is a prerequisite in this case.
[Advanced Linux System Administration][29]
### Linux System Administration [eBook]
Another free eBook by Paul Cobbaut. The 370 pages long eBook covers networking, disk management, user management, kernel management, library management etc.
[Linux System Administration][30]
### Linux Servers [eBook]
One more eBook from Paul Cobbaut of [linux-training.be][31]. This book covers web servers, mysql, DHCP, DNS, Samba and other file servers.
[Linux Servers][32]
### Linux Networking [eBook]
Networking is the bread and butter of a SysAdmin, and this book by Paul Cobbaut (again) is a good reference material.
[Linux Networking][33]
### Linux Storage [eBook]
This book by Paul Cobbaut (yes, him again) explains disk management on Linux in detail and introduces a lot of other storage-related technologies.
[Linux Storage][34]
### Linux Security [eBook]
This is the last eBook by Paul Cobbaut in our list here. Security is one of the most important part of a sysadmin's job. This book focuses on file permissions, acls, SELinux, users and passwords etc.
[Linux Security][35]
## Your favorite Linux learning material?
I know that this is a good collection of free Linux eBooks. But this could always be made better.
If you have some other resources that could be helpful in learning Linux, do share with us. Please note to share only the legal downloads so that I can update this article with your suggestion(s) without any problem.
I hope you find this article helpful in learning Linux. Your feedback is welcome :)
--------------------------------------------------------------------------------
via: https://itsfoss.com/learn-linux-for-free/
作者:[Abhishek Prakash][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://itsfoss.com/author/abhishek/
[1]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2017/02/free-ebooks-linux-800x450.png
[2]:https://www.linuxfoundation.org/
[3]:https://www.edx.org
[4]:https://www.youtube.com/watch?v=eE-ovSOQK0Y
[5]:https://www.edx.org/course/introduction-linux-linuxfoundationx-lfs101x-0
[6]:https://linuxjourney.com/
[7]:https://www.linuxtrainingacademy.com/
[8]:https://courses.linuxtrainingacademy.com/itsfoss-ll5d/
[9]:https://linuxnewbieguide.org/ulngebook/
[10]:http://www.tldp.org/index.html
[11]:http://tldp.org/LDP/intro-linux/intro-linux.pdf
[12]:http://linux-training.be/linuxfun.pdf
[13]:http://advancedlinuxprogramming.com/alp-folder/advanced-linux-programming.pdf
[14]:http://www.linuxfromscratch.org/
[15]:http://tldp.org/LDP/GNU-Linux-Tools-Summary/GNU-Linux-Tools-Summary.pdf
[16]:https://www.gnu.org/home.en.html
[17]:https://www.gnu.org/software/bash/manual/bash.pdf
[18]:http://linuxcommand.org/tlcl.php
[19]:http://www.tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf
[20]:http://www.tldp.org/LDP/abs/abs-guide.pdf
[21]:https://ia802309.us.archive.org/25/items/pdfy-MgN0H1joIoDVoIC7/The_AWK_Programming_Language.pdf
[22]:http://www.thegeekstuff.com/linux-101-hacks-ebook/
[23]:https://ubuntu-manual.org/
[24]:http://downtoearthlinux.com/resources/just-tell-me-damnit/
[25]:https://drive.google.com/file/d/0B5Ymf8oYXx-PWTVJR0pmM3daZUE/view
[26]:https://en.wikipedia.org/wiki/LAMP_(software_bundle)
[27]:https://debian-handbook.info/about-the-book/
[28]:https://www.lpi.org/our-certifications/getting-started
[29]:http://www.nongnu.org/lpi-manuals/manual/pdf/GNU-FDL-OO-LPI-201-0.1.pdf
[30]:http://linux-training.be/linuxsys.pdf
[31]:http://linux-training.be/
[32]:http://linux-training.be/linuxsrv.pdf
[33]:http://linux-training.be/linuxnet.pdf
[34]:http://linux-training.be/linuxsto.pdf
[35]:http://linux-training.be/linuxsec.pdf

View File

@ -1,3 +1,4 @@
ch-cn translating
5 SSH alias examples in Linux
======
[![][1]][1]

View File

@ -1,137 +0,0 @@
translating---geekpi
Easy guide to secure VNC server with TLS encryption
======
In this tutorial, we will learn to install VNC server & secure VNC server sessions with TLS encryption.
This method has been tested on CentOS 6 & 7 but should work on other versions/OS as well (RHEL, Scientific Linux etc).
**(Recommended Read:[Ultimate guide for Securing SSH sessions][1] )**
### Installing VNC server
Before we install VNC server on our machines, make sure we are have a working GUI. If GUI is not installed on our machine, we can install it by executing the following command,
```
yum groupinstall "GNOME Desktop"
```
Now we will tigervnc as our VNC server, to install it run,
```
# yum install tigervnc-server
```
Once VNC server has been installed, we will create a new user to access the server,
```
# useradd vncuser
```
& assign it a password for accessing VNC by using following command,
```
# vncpasswd vncuser
```
Now we have a little change in configuration on CentOS 6 & 7, we will first address the CentOS 6 configuration,
#### CentOS 6
Now we need to edit VNC configuration file,
```
**# vim /etc/sysconfig/vncservers**
```
& add the following lines,
```
[ …]
VNCSERVERS= "1:vncuser"
VNCSERVERARGS[1]= "-geometry 1024×768″
```
Save the file & exit. Next restart the vnc service to implement the changes,
```
# service vncserver restart
```
& enable it at boot,
```
# chkconfig vncserver on
```
#### CentOS 7
On CentOS 7, /etc/sysconfig/vncservers file has been changed to /lib/systemd/system/vncserver@.service. We will use this configuration file as reference, so create a copy of the file,
```
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
```
Next we will edit the file to include our created user,
```
# vim /etc/systemd/system/vncserver@:1.service
```
& edit the user on the following 2 lines,
```
ExecStart=/sbin/runuser -l vncuser -c "/usr/bin/vncserver %i"
PIDFile=/home/vncuser/.vnc/%H%i.pid
```
Save file & exit. Next restart the service & enable it at boot,
```
systemctl restart[[email protected]][2]:1.service
systemctl enable[[email protected]][2]:1.service
```
We now have our VNC server ready & can connect to it from a client machine using the IP address of VNC server. But we before we do that, we will secure our connections with TLS encryption.
### Securing the VNC session
To secure VNC server session, we will first configure the encryption method to secure VNC server sessions. We will be using TLS encryption but can also use SSL encryption. Execute the following command to start using TLS encrytption on VNC server,
```
# vncserver -SecurityTypes=VeNCrypt,TLSVnc
```
You will asked to enter a password to access VNC (if using any other user, than the above mentioned user)
![secure vnc server][4]
We can now access the server using the VNC viewer from the client machine, use the following command to start vnc viewer with secure connection,
**# vncviewer -SecurityTypes=VeNCrypt,TLSVnc 192.168.1.45:1**
here, 192.168.1.45 is the IP address of the VNC server.
![secure vnc server][6]
Enter the password & we can than access the server remotely & that too with TLS encryption.
This completes our tutorial, feel free to send your suggestions or queries using the comment box below.
--------------------------------------------------------------------------------
via: http://linuxtechlab.com/secure-vnc-server-tls-encryption/
作者:[Shusain][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linuxtechlab.com/author/shsuain/
[1]:http://linuxtechlab.com/ultimate-guide-to-securing-ssh-sessions/
[2]:/cdn-cgi/l/email-protection
[3]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=642%2C241
[4]:https://i1.wp.com/linuxtechlab.com/wp-content/uploads/2017/10/secure_vnc-1.png?resize=642%2C241
[5]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=665%2C419
[6]:https://i2.wp.com/linuxtechlab.com/wp-content/uploads/2017/10/secure_vnc-2.png?resize=665%2C419

View File

@ -1,131 +0,0 @@
translating by ucasFL
How to generate webpages using CGI scripts
======
Back in the stone age of the Internet when I first created my first business website, life was good.
I installed Apache and created a few simple HTML pages that stated a few important things about my business and gave important information like an overview of my product and how to contact me. It was a static website because the content seldom changed. Maintenance was simple because of the unchanging nature of my site.
## Static content
Static content is easy and still common. Let's take a quick look at a couple sample static web pages. You don't need a working website to perform these little experiments. Just place the files in your home directory and open them with your browser. You will see exactly what you would if the file were served to your browser via a web server.
The first thing you need on a static website is the index.html file which is usually located in the /var/www/html directory. This file can be as simple as a text phrase such as "Hello world" without any HTML markup at all. This would simply display the text string. Create index.html in your home directory and add "Hello world" (without the quotes) as it's only content. Open the index.html in your browser with the following URL.
```
file:///home/<yourhomedirectory>/index.html
```
So HTML is not required, but if you had a large amount of text that needed formatting, the results of a web page with no HTML coding would be incomprehensible with everything running together.
So the next step is to make the content more readable by using a bit of HTML coding to provide some formatting. The following command creates a page with the absolute minimum markup required for a static web page with HTML. You could also use your favorite editor to create the content.
```
echo "<h1>Hello World</h1>" > test1.html
```
Now view index.html and see the difference.
Of course you can put a lot of additional HTML around the actual content line to make a more complete and standard web page. That more complete version as shown below will still display the same results in the browser, but it also forms the basis for more standardized web site. Go ahead and use this content for your index.html file and display it in your browser.
```
<!DOCTYPE HTML PUBLIC "-//w3c//DD HTML 4.0//EN">
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
```
I built a couple static websites using these techniques, but my life was about to change.
## Dynamic web pages for a new job
I took a new job in which my primary task was to create and maintain the CGI ([Common Gateway Interface][6]) code for a very dynamic website. In this context, dynamic means that the HTML needed to produce the web page on a browser was generated from data that could be different every time the page was accessed. This includes input from the user on a web form that is used to look up data in a database. The resulting data is surrounded by appropriate HTML and displayed on the requesting browser. But it does not need to be that complex.
Using CGI scripts for a website allows you to create simple or complex interactive programs that can be run to provide a dynamic web page that can change based on input, calculations, current conditions in the server, and so on. There are many languages that can be used for CGI scripts. We will look at two of them, Perl and Bash. Other popular CGI languages include PHP and Python.
This article does not cover installation and setup of Apache or any other web server. If you have access to a web server that you can experiment with, you can directly view the results as they would appear in a browser. Otherwise, you can still run the programs from the command line and view the HTML that would be created. You can also redirect that HTML output to a file and then display the resulting file in your browser.
### Using Perl
Perl is a very popular language for CGI scripts. Its strength is that it is a very powerful language for the manipulation of text.
To get CGI scripts to execute, you need the following line in the in httpd.conf for the website you are using. This tells the web server where your executable CGI files are located. For this experiment, let's not worry about that.
```
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
```
Add the following Perl code to the file index.cgi, which should be located in your home directory for your experimentation. Set the ownership of the file to apache.apache when you use a web server, and set the permissions to 755 because it must be executable no matter where it is located.
```
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><body>\n";
print "<h1>Hello World</h1>\n";
print "Using Perl<p>\n";
print "</body></html>\n";
```
Run this program from the command line and view the results. It should display the HTML code it will generate.
Now view the index.cgi in your browser. Well, all you get is the contents of the file. Browsers really need to have this delivered as CGI content. Apache does not really know that it needs to run the file as a CGI program unless the Apache configuration for the web site includes the "ScriptAlias" definition as shown above. Without that bit of configuration Apache simply send the data in the file to the browser. If you have access to a web server, you could try this out with your executable index files in the /var/www/cgi-bin directory.
To see what this would look like in your browser, run the program again and redirect the output to a new file. Name it whatever you want. Then use your browser to view the file that contains the generated content.
The above CGI program is still generating static content because it always displays the same output. Add the following line to your CGI program immediately after the "Hello World" line. The Perl "system" command executes the commands following it in a system shell, and returns the result to the program. In this case, we simply grep the current RAM usage out of the results from the free command.
```
system "free | grep Mem\n";
```
Now run the program again and redirect the output to the results file. Reload the file in the browser. You should see an additional line so that displays the system memory statistics. Run the program and refresh the browser a couple more times and notice that the memory usage should change occasionally.
### Using Bash
Bash is probably the simplest language of all for use in CGI scripts. Its primary strength for CGI programming is that it has direct access to all of the standard GNU utilities and system programs.
Rename the existing index.cgi to Perl.index.cgi and create a new index.cgi with the following content. Remember to set the permissions correctly to executable.
```
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Hello World</title>'
echo '</head>'
echo '<body>'
echo '<h1>Hello World</h1><p>'
echo 'Using Bash<p>'
free | grep Mem
echo '</body>'
echo '</html>'
exit 0
```
Execute this program from the command line and view the output, then run it and redirect the output to the temporary results file you created before. Then refresh the browser to view what it looks like displayed as a web page.
## Conclusion
It is actually very simple to create CGI programs that can be used to generate a wide range of dynamic web pages. This is a trivial example but you should now see some of the possibilities.
--------------------------------------------------------------------------------
via: https://opensource.com/article/17/12/cgi-scripts
作者:[David Both][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/dboth
[1]:http://december.com/html/4/element/html.html
[2]:http://december.com/html/4/element/head.html
[3]:http://december.com/html/4/element/title.html
[4]:http://december.com/html/4/element/body.html
[5]:http://december.com/html/4/element/h1.html
[6]:https://en.wikipedia.org/wiki/Common_Gateway_Interface
[7]:http://perldoc.perl.org/functions/system.html

View File

@ -1,132 +0,0 @@
translated by cyleft
Linux tee Command Explained for Beginners (6 Examples)
======
There are times when you want to manually track output of a command and also simultaneously make sure the output is being written to a file so that you can refer to it later. If you are looking for a Linux tool which can do this for you, you'll be glad to know there exists a command **tee** that's built for this purpose.
In this tutorial, we will discuss the basics of the tee command using some easy to understand examples. But before we do that, it's worth mentioning that all examples used in this article have been tested on Ubuntu 16.04 LTS.
### Linux tee command
The tee command basically reads from the standard input and writes to standard output and files. Following is the syntax of the command:
```
tee [OPTION]... [FILE]...
```
And here's how the man page explains it:
```
Copy standard input to each FILE, and also to standard output.
```
The following Q&A-styled examples should give you a better idea on how the command works.
### Q1. How to use tee command in Linux?
Suppose you are using the ping command for some reason.
ping google.com
[![How to use tee command in Linux][1]][2]
And what you want, is that the output should also get written to a file in parallel. Then here's where you can use the tee command.
```
ping google.com | tee output.txt
```
The following screenshot shows the output was written to the 'output.txt' file along with being written on stdout.
[![tee command output][3]][4]
So that should clear the basic usage of tee.
### Q2. How to make sure tee appends information in files?
By default, the tee command overwrites information in a file when used again. However, if you want, you can change this behavior by using the -a command line option.
```
[command] | tee -a [file]
```
So basically, the -a option forces tee to append information to the file.
### Q3. How to make tee write to multiple files?
That's pretty easy. You just have to mention their names.
```
[command] | tee [file1] [file2] [file3]
```
For example:
```
ping google.com | tee output1.txt output2.txt output3.txt
```
[![How to make tee write to multiple files][5]][6]
### Q4. How to make tee redirect output of one command to another?
You can not only use tee to simultaneously write output to files, but also to pass on the output as input to other commands. For example, the following command will not only store the filenames in 'output.txt' but also let you know - through wc - the number of entries in the output.txt file.
```
ls file* | tee output.txt | wc -l
```
[![How to make tee redirect output of one command to another][7]][8]
### Q5. How to write to a file with elevated privileges using tee?
Suppose you opened a file in the [Vim editor][9], made a lot of changes, and then when you tried saving those changes, you got an error that made you realize that it's a root-owned file, meaning you need to have sudo privileges to save these changes.
[![How to write to a file with elevated privileges using tee][10]][11]
In scenarios like these, you can use tee to elevate privileges on the go.
```
:w !sudo tee %
```
The aforementioned command will ask you for root password, and then let you save the changes.
### Q6. How to make tee ignore interrupt?
The -i command line option enables tee to ignore the interrupt signal (`SIGINT`), which is usually issued when you press the crl+c key combination.
```
[command] | tee -i [file]
```
This is useful when you want to kill the command with ctrl+c but want tee to exit gracefully.
### Conclusion
You'll likely agree now that tee is an extremely useful command. We've discussed it's basic usage as well as majority of its command line options here. The tool doesn't have a steep learning curve, so just practice all these examples, and you should be good to go. For more information, head to the tool's [man page][12].
--------------------------------------------------------------------------------
via: https://www.howtoforge.com/linux-tee-command/
作者:[Himanshu Arora][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.howtoforge.com
[1]:https://www.howtoforge.com/images/command-tutorial/ping-example.png
[2]:https://www.howtoforge.com/images/command-tutorial/big/ping-example.png
[3]:https://www.howtoforge.com/images/command-tutorial/ping-with-tee.png
[4]:https://www.howtoforge.com/images/command-tutorial/big/ping-with-tee.png
[5]:https://www.howtoforge.com/images/command-tutorial/tee-mult-files1.png
[6]:https://www.howtoforge.com/images/command-tutorial/big/tee-mult-files1.png
[7]:https://www.howtoforge.com/images/command-tutorial/tee-redirect-output.png
[8]:https://www.howtoforge.com/images/command-tutorial/big/tee-redirect-output.png
[9]:https://www.howtoforge.com/vim-basics
[10]:https://www.howtoforge.com/images/command-tutorial/vim-write-error.png
[11]:https://www.howtoforge.com/images/command-tutorial/big/vim-write-error.png
[12]:https://linux.die.net/man/1/tee

View File

@ -1,3 +1,4 @@
translating by wenwensnow
Shell Scripting a Bunco Game
======
I haven't dug into any game programming for a while, so I thought it was high time to do something in that realm. At first, I thought "Halo as a shell script?", but then I came to my senses. Instead, let's look at a simple dice game called Bunco. You may not have heard of it, but I bet your Mom has—it's a quite popular game for groups of gals at a local pub or tavern.

View File

@ -1,97 +0,0 @@
translating by ucasFL
Linux mkdir Command Explained for Beginners (with examples)
======
At any given time on the command line, you are in a directory. So it speaks for itself how integral directories are to the command line. In Linux, while the rm command lets you delete directories, it's the **mkdir** command that allows you create them in the first place. In this tutorial, we will discuss the basics of this tool using some easy to understand examples.
But before we do that, it's worth mentioning that all examples in this tutorial have been tested on Ubuntu 16.04 LTS.
### Linux mkdir command
As already mentioned, the mkdir command allows the user to create directories. Following is its syntax:
```
mkdir [OPTION]... DIRECTORY...
```
And here's how the tool's man page describes it:
```
Create the DIRECTORY(ies), if they do not already exist.
```
The following Q&A-styled examples should give you a better idea on how mkdir works.
### Q1. How to create directories using mkdir?
Creating directories is pretty simple, all you need to do is to pass the name of the directory you want to create to the mkdir command.
```
mkdir [dir-name]
```
Following is an example:
```
mkdir test-dir
```
### Q2. How to make sure parent directories (if non-existent) are created in process?
Sometimes the requirement is to create a complete directory structure with a single mkdir command. This is possible, but you'll have to use the **-p** command line option.
For example, if you want to create dir1/dir2/dir2 when none of these directories are already existing, then you can do this in the following way:
```
mkdir -p dir1/dir2/dir3
```
[![How to make sure parent directories \(if non-existent\) are created][1]][2]
### Q3. How to set permissions for directory being created?
By default, the mkdir command sets rwx, rwx, and r-x permissions for the directories created through it.
[![How to set permissions for directory being created][3]][4]
However, if you want, you can set custom permissions using the **-m** command line option.
[![mkdir -m command option][5]][6]
### Q4. How to make mkdir emit details of operation?
In case you want mkdir to display complete details of the operation it's performing, then this can be done through the **-v** command line option.
```
mkdir -v [dir]
```
Here's an example:
[![How to make mkdir emit details of operation][7]][8]
### Conclusion
So you can see mkdir is a pretty simple command to understand and use. It doesn't have any learning curve associated with it. We have covered almost all of its command line options here. Just practice them and you can start using the command in your day-to-day work. In case you want to know more about the tool, head to its [man page][9].
--------------------------------------------------------------------------------
via: https://www.howtoforge.com/linux-mkdir-command/
作者:[Himanshu Arora][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.howtoforge.com
[1]:https://www.howtoforge.com/images/command-tutorial/mkdir-p.png
[2]:https://www.howtoforge.com/images/command-tutorial/big/mkdir-p.png
[3]:https://www.howtoforge.com/images/command-tutorial/mkdir-def-perm.png
[4]:https://www.howtoforge.com/images/command-tutorial/big/mkdir-def-perm.png
[5]:https://www.howtoforge.com/images/command-tutorial/mkdir-custom-perm.png
[6]:https://www.howtoforge.com/images/command-tutorial/big/mkdir-custom-perm.png
[7]:https://www.howtoforge.com/images/command-tutorial/mkdir-verbose.png
[8]:https://www.howtoforge.com/images/command-tutorial/big/mkdir-verbose.png
[9]:https://linux.die.net/man/1/mkdir

View File

@ -1,3 +1,5 @@
translating---geekpi
4 cool new projects to try in COPR for January
======

View File

@ -0,0 +1,272 @@
8 ways to generate random password in Linux
======
Learn 8 different ways to generate random password in Linux using Linux native commands or third party utilities.
![][1]
In this article, we will walk you through various different ways to generate random password in Linux terminal. Few of them are using native Linux commands and others are using third party tools or utilities which can easily be installed on Linux machine. Here we are looking at native commands like `openssl`, [dd][2], `md5sum`, `tr`, `urandom` and third party tools like mkpasswd, randpw, pwgen, spw, gpg, xkcdpass, diceware, revelation, keepaasx, passwordmaker.
These are actually ways to get some random alphanumeric string which can be utilized as password. Random passwords can be used for new users so that there will be uniqueness no matter how large your user base is. Without any further delay lets jump into those 15 different ways to generate random password in Linux.
##### Generate password using mkpasswd utility
`mkpasswd` comes with install of `expect` package on RHEL based systems. On Debian based systems `mkpasswd` comes with package `whois`. Trying to install `mkpasswd` package will results in error -
No package mkpasswd available. on RHEL system and E: Unable to locate package mkpasswd in Debian based.
So install their parent packages as mentioned above and you are good to go.
Run `mkpasswd` to get passwords
```
root@kerneltalks# mkpasswd << on RHEL
zt*hGW65c
root@kerneltalks# mkpas
```
Command behaves differently on different systems so work accordingly. There are many switches which can be used to control length etc parameters. You can explore them from man pages.
##### Generate password using openssl
Openssl comes in build with almost all the Linux distributions. We can use its random function to get alphanumeric string generated which can be used as password.
```
root@kerneltalks # openssl rand -base64 10
nU9LlHO5nsuUvw==
```
Here, we are using `base64` encoding with random function and last digit for argument to `base64` encoding.
##### Generate password using urandom
Device file `/dev/urandom` is another source of getting random characters. We are using `tr` function and trimming output to get random string to use as password.
```
root@kerneltalks # strings /dev/urandom |tr -dc A-Za-z0-9 | head -c20; echo
UiXtr0NAOSIkqtjK4c0X
```
##### dd command to generate password
We can even use /dev/urandom device along with [dd command ][2]to get string of random characters.
```
oot@kerneltalks# dd if=/dev/urandom bs=1 count=15|base64 -w 0
15+0 records in
15+0 records out
15 bytes (15 B) copied, 5.5484e-05 s, 270 kB/s
QMsbe2XbrqAc2NmXp8D0
```
We need to pass output through `base64` encoding to make it human readable. You can play with count value to get desired length. For much cleaner output, redirect std2 to `/dev/null`. Clean command will be -
```
oot@kerneltalks # dd if=/dev/urandom bs=1 count=15 2>/dev/null|base64 -w 0
F8c3a4joS+a3BdPN9C++
```
##### Using md5sum to generate password
Another way to get array of random characters which can be used as password is to calculate MD5 checksum! s you know checksum value is indeed looks like random characters grouped together we can use it as password. Make sure you use source as something variable so that you get different checksum every time you run command. For example `date` ! [date command][3] always yields changing output.
```
root@kerneltalks # date |md5sum
4d8ce5c42073c7e9ca4aeffd3d157102 -
```
Here we passed `date` command output to `md5sum` and get the checksum hash! You can use [cut command][4] to get desired length of output.
##### Generate password using pwgen
`pwgen` package comes with [repositories like EPEL][5]. `pwgen` is more focused on generating passwords which are pronounceable but not a dictionary word or not in plain English. You may not find it in standard distribution repo. Install the package and run `pwgen` command. Boom !
```
root@kerneltalks # pwgen
thu8Iox7 ahDeeQu8 Eexoh0ai oD8oozie ooPaeD9t meeNeiW2 Eip6ieph Ooh1tiet
cootad7O Gohci0vo wah9Thoh Ohh3Ziur Ao1thoma ojoo6aeW Oochai4v ialaiLo5
aic2OaDa iexieQu8 Aesoh4Ie Eixou9ph ShiKoh0i uThohth7 taaN3fuu Iege0aeZ
cah3zaiW Eephei0m AhTh8guo xah1Shoo uh8Iengo aifeev4E zoo4ohHa fieDei6c
aorieP7k ahna9AKe uveeX7Hi Ohji5pho AigheV7u Akee9fae aeWeiW4a tiex8Oht
```
You will be presented with list of passwords at your terminal! What else you want? Ok. You still want to explore, `pwgen` comes with many custom options which can be referred for man page.
##### Generate password using gpg tool
GPG is a OpenPGP encryption and signing tool. Mostly gpg tool comes pre-installed (at least it is on my RHEL7). But if not you can look for `gpg` or `gpg2` package and [install][6] it.
Use below command to generate password from gpg tool.
```
root@kerneltalks # gpg --gen-random --armor 1 12
mL8i+PKZ3IuN6a7a
```
Here we are passing generate random byte sequence switch (`--gen-random`) of quality 1 (first argument) with count of 12 (second argument). Switch `--armor` ensures output is `base64` encoded.
##### Generate password using xkcdpass
Famous geek humor website [xkcd][7], published a very interesting post about memorable but still complex passwords. You can view it [here][8]. So `xkcdpass` tool took inspiration from this post and did its work! Its a python package and available on python's official website [here][9]
All installation and usage instructions are mentioned on that page. Here is install steps and outputs from my test RHEL server for your reference.
```
root@kerneltalks # wget https://pypi.python.org/packages/b4/d7/3253bd2964390e034cf0bba227db96d94de361454530dc056d8c1c096abc/xkcdpass-1.14.3.tar.gz#md5=5f15d52f1d36207b07391f7a25c7965f
--2018-01-23 19:09:17-- https://pypi.python.org/packages/b4/d7/3253bd2964390e034cf0bba227db96d94de361454530dc056d8c1c096abc/xkcdpass-1.14.3.tar.gz
Resolving pypi.python.org (pypi.python.org)... 151.101.32.223, 2a04:4e42:8::223
Connecting to pypi.python.org (pypi.python.org)|151.101.32.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 871848 (851K) [binary/octet-stream]
Saving to: xkcdpass-1.14.3.tar.gz
100%[==============================================================================================================================>] 871,848 --.-K/s in 0.01s
2018-01-23 19:09:17 (63.9 MB/s) - xkcdpass-1.14.3.tar.gz saved [871848/871848]
root@kerneltalks # tar -xvf xkcdpass-1.14.3.tar.gz
xkcdpass-1.14.3/
xkcdpass-1.14.3/examples/
xkcdpass-1.14.3/examples/example_import.py
xkcdpass-1.14.3/examples/example_json.py
xkcdpass-1.14.3/examples/example_postprocess.py
xkcdpass-1.14.3/LICENSE.BSD
xkcdpass-1.14.3/MANIFEST.in
xkcdpass-1.14.3/PKG-INFO
xkcdpass-1.14.3/README.rst
xkcdpass-1.14.3/setup.cfg
xkcdpass-1.14.3/setup.py
xkcdpass-1.14.3/tests/
xkcdpass-1.14.3/tests/test_list.txt
xkcdpass-1.14.3/tests/test_xkcdpass.py
xkcdpass-1.14.3/tests/__init__.py
xkcdpass-1.14.3/xkcdpass/
xkcdpass-1.14.3/xkcdpass/static/
xkcdpass-1.14.3/xkcdpass/static/eff-long
xkcdpass-1.14.3/xkcdpass/static/eff-short
xkcdpass-1.14.3/xkcdpass/static/eff-special
xkcdpass-1.14.3/xkcdpass/static/fin-kotus
xkcdpass-1.14.3/xkcdpass/static/ita-wiki
xkcdpass-1.14.3/xkcdpass/static/legacy
xkcdpass-1.14.3/xkcdpass/static/spa-mich
xkcdpass-1.14.3/xkcdpass/xkcd_password.py
xkcdpass-1.14.3/xkcdpass/__init__.py
xkcdpass-1.14.3/xkcdpass.1
xkcdpass-1.14.3/xkcdpass.egg-info/
xkcdpass-1.14.3/xkcdpass.egg-info/dependency_links.txt
xkcdpass-1.14.3/xkcdpass.egg-info/entry_points.txt
xkcdpass-1.14.3/xkcdpass.egg-info/not-zip-safe
xkcdpass-1.14.3/xkcdpass.egg-info/PKG-INFO
xkcdpass-1.14.3/xkcdpass.egg-info/SOURCES.txt
xkcdpass-1.14.3/xkcdpass.egg-info/top_level.txt
root@kerneltalks # cd xkcdpass-1.14.3
root@kerneltalks # python setup.py install
running install
running bdist_egg
running egg_info
writing xkcdpass.egg-info/PKG-INFO
writing top-level names to xkcdpass.egg-info/top_level.txt
writing dependency_links to xkcdpass.egg-info/dependency_links.txt
writing entry points to xkcdpass.egg-info/entry_points.txt
reading manifest file 'xkcdpass.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'xkcdpass.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/xkcdpass
copying xkcdpass/xkcd_password.py -> build/lib/xkcdpass
copying xkcdpass/__init__.py -> build/lib/xkcdpass
creating build/lib/xkcdpass/static
copying xkcdpass/static/eff-long -> build/lib/xkcdpass/static
copying xkcdpass/static/eff-short -> build/lib/xkcdpass/static
copying xkcdpass/static/eff-special -> build/lib/xkcdpass/static
copying xkcdpass/static/fin-kotus -> build/lib/xkcdpass/static
copying xkcdpass/static/ita-wiki -> build/lib/xkcdpass/static
copying xkcdpass/static/legacy -> build/lib/xkcdpass/static
copying xkcdpass/static/spa-mich -> build/lib/xkcdpass/static
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/xkcdpass
copying build/lib/xkcdpass/xkcd_password.py -> build/bdist.linux-x86_64/egg/xkcdpass
copying build/lib/xkcdpass/__init__.py -> build/bdist.linux-x86_64/egg/xkcdpass
creating build/bdist.linux-x86_64/egg/xkcdpass/static
copying build/lib/xkcdpass/static/eff-long -> build/bdist.linux-x86_64/egg/xkcdpass/static
copying build/lib/xkcdpass/static/eff-short -> build/bdist.linux-x86_64/egg/xkcdpass/static
copying build/lib/xkcdpass/static/eff-special -> build/bdist.linux-x86_64/egg/xkcdpass/static
copying build/lib/xkcdpass/static/fin-kotus -> build/bdist.linux-x86_64/egg/xkcdpass/static
copying build/lib/xkcdpass/static/ita-wiki -> build/bdist.linux-x86_64/egg/xkcdpass/static
copying build/lib/xkcdpass/static/legacy -> build/bdist.linux-x86_64/egg/xkcdpass/static
copying build/lib/xkcdpass/static/spa-mich -> build/bdist.linux-x86_64/egg/xkcdpass/static
byte-compiling build/bdist.linux-x86_64/egg/xkcdpass/xkcd_password.py to xkcd_password.pyc
byte-compiling build/bdist.linux-x86_64/egg/xkcdpass/__init__.py to __init__.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying xkcdpass.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xkcdpass.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xkcdpass.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xkcdpass.egg-info/entry_points.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xkcdpass.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying xkcdpass.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
creating dist
creating 'dist/xkcdpass-1.14.3-py2.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing xkcdpass-1.14.3-py2.7.egg
creating /usr/lib/python2.7/site-packages/xkcdpass-1.14.3-py2.7.egg
Extracting xkcdpass-1.14.3-py2.7.egg to /usr/lib/python2.7/site-packages
Adding xkcdpass 1.14.3 to easy-install.pth file
Installing xkcdpass script to /usr/bin
Installed /usr/lib/python2.7/site-packages/xkcdpass-1.14.3-py2.7.egg
Processing dependencies for xkcdpass==1.14.3
Finished processing dependencies for xkcdpass==1.14.3
```
Now running xkcdpass command will give you random set of dictionary words like below -
```
root@kerneltalks # xkcdpass
broadside unpadded osmosis statistic cosmetics lugged
```
You can use these words as input to other commands like `md5sum` to get random password (like below) or you can even use Nth letter of each words to form your password!
```
oot@kerneltalks # xkcdpass |md5sum
45f2ec9b3ca980c7afbd100268c74819 -
root@kerneltalks # xkcdpass |md5sum
ad79546e8350744845c001d8836f2ff2 -
```
Or even you can use all those words together as such a long password which is easy to remember for a user and very hard to crack using computer program.
There are tools like [Diceware][10], [KeePassX][11], [Revelation][12], [PasswordMaker][13] for Linux which can be considered for making strong random passwords.
--------------------------------------------------------------------------------
via: https://kerneltalks.com/tips-tricks/8-ways-to-generate-random-password-in-linux/
作者:[kerneltalks][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://kerneltalks.com
[1]:https://a1.kerneltalks.com/wp-content/uploads/2018/01/different-ways-to-generate-password-in-linux.png
[2]:https://kerneltalks.com/commands/learn-dd-command-with-examples/
[3]:https://kerneltalks.com/commands/date-time-management-using-timedatectl-command/
[4]:https://kerneltalks.com/linux/cut-command-examples/
[5]:https://kerneltalks.com/package/how-to-install-epel-repository/
[6]:https://kerneltalks.com/tools/package-installation-linux-yum-apt/
[7]:https://xkcd.com/
[8]:https://xkcd.com/936/
[9]:https://pypi.python.org/pypi/xkcdpass/
[10]:http://world.std.com/~reinhold/diceware.html
[11]:https://www.keepassx.org/
[12]:https://packages.debian.org/sid/gnome/revelation
[13]:https://passwordmaker.org/

View File

@ -0,0 +1,130 @@
A step-by-step guide to Git
======
![](https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/lightbulb-idea-think-yearbook-lead.png?itok=5ZpCm0Jh)
If you've never used [Git][1], you may be nervous about it. There's nothing to worry about--just follow along with this step-by-step getting-started guide, and you will soon have a new Git repository hosted on [GitHub][2].
Before we dive in, let's clear up a common misconception: Git isn't the same thing as GitHub. Git is a version-control system (i.e., a piece of software) that helps you keep track of your computer programs and files and the changes that are made to them over time. It also allows you to collaborate with your peers on a program, code, or file. GitHub and similar services (including GitLab and BitBucket) are websites that host a Git server program to hold your code.
### Step 1: Create a GitHub account
The easiest way to get started is to create an account on [GitHub.com][3] (it's free).
![](https://opensource.com/sites/default/files/u128651/git_guide1.png)
Pick a username (e.g., octocat123), enter your email address and a password, and click **Sign up for GitHub**. Once you are in, it will look something like this:
![](https://opensource.com/sites/default/files/u128651/git_guide2.png)
### Step 2: Create a new repository
A repository is like a place or a container where something is stored; in this case we're creating a Git repository to store code. To create a new repository, select **New Repository** from the `+` sign dropdown menu (you can see I've selected it in the upper-right corner in the image above).
![](https://opensource.com/sites/default/files/u128651/git_guide3.png)
Enter a name for your repository (e.g, "Demo") and click **Create Repository**. Don't worry about changing any other options on this page.
Congratulations! You have set up your first repo on GitHub.com.
### Step 3: Create a file
Once your repo is created, it will look like this:
![](https://opensource.com/sites/default/files/u128651/git_guide4.png)
Don't panic, it's simpler than it looks. Stay with me. Look at the section that starts "...or create a new repository on the command line," and ignore the rest for now.
Open the Terminal program on your computer.
![](https://opensource.com/sites/default/files/u128651/git_guide5.png)
Type `git` and hit **Enter**. If it says command `bash: git: command not found`, then [install Git][4] with the command for your Linux operating system or distribution. Check the installation by typing `git` and hitting **Enter** ; if it's installed, you should see a bunch of information about how you can use the command.
In the terminal, type:
```
mkdir Demo
```
This command will create a directory (or folder) named Demo.
Change your terminal to the Demo directory with the command:
```
cd Demo
```
Then enter:
```
echo "#Demo" >> README.md
```
This creates a file named `README.md` and writes `#Demo` in it. To check that the file was created successfully, enter:
```
cat README.md
```
This will show you what is inside the `README.md` file, if the file was created correctly. Your terminal will look like this:
![](https://opensource.com/sites/default/files/u128651/git_guide7.png)
To tell your computer that Demo is a directory managed by the Git program, enter:
```
git init
```
Then, to tell the Git program you care about this file and want to track any changes from this point forward, enter:
```
git add README.md
```
### Step 4: Make a commit
So far you've created a file and told Git about it, and now it's time to create a commit. Commit can be thought of as a milestone. Every time you accomplish some work, you can write a Git commit to store that version of your file, so you can go back later and see what it looked like at that point in time. Whenever you make a change to your file, you create a new version of that file, different from the previous one.
To make a commit, enter:
```
git commit -m "first commit"
```
That's it! You just created a Git commit and included a message that says first commit. You must always write a message in commit; it not only helps you identify a commit, but it also enables you to understand what you did with the file at that point. So tomorrow, if you add a new piece of code in your file, you can write a commit message that says, Added new code, and when you come back in a month to look at your commit history or Git log (the list of commits), you will know what you changed in the files.
### Step 5: Connect your GitHub repo with your computer
Now, it's time to connect your computer to GitHub with the command:
```
git remote add origin https://github.com/<your_username>/Demo.git
```
Let's look at this command step by step. We are telling Git to add a `remote` called `origin` with the address `https://github.com/<your_username>/Demo.git` (i.e., the URL of your Git repo on GitHub.com). This allows you to interact with your Git repository on GitHub.com by typing `origin` instead of the full URL and Git will know where to send your code. Why `origin`? Well, you can name it anything else if you'd like.
Now we have connected our local copy of the Demo repository to its remote counterpart on GitHub.com. Your terminal looks like this:
![](https://opensource.com/sites/default/files/u128651/git_guide8.png)
Now that we have added the remote, we can push our code (i.e., upload our `README.md` file) to GitHub.com.
Once you are done, your terminal will look like this:
![](https://opensource.com/sites/default/files/u128651/git_guide9.png)
And if you go to `https://github.com/<your_username>/Demo` you will see something like this:
![](https://opensource.com/sites/default/files/u128651/git_guide10.png)
That's it! You have created your first GitHub repo, connected it to your computer, and pushed (or uploaded) a file from your computer to your repository called Demo on GitHub.com. Next time, I will write about Git cloning (downloading your code from GitHub to your computer), adding new files, modifying existing files, and pushing (uploading) files to GitHub.
--------------------------------------------------------------------------------
via: https://opensource.com/article/18/1/step-step-guide-git
作者:[Kedar Vijay Kulkarni][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/kkulkarn
[1]:https://opensource.com/resources/what-is-git
[2]:https://opensource.com/life/15/11/short-introduction-github
[3]:https://github.com/
[4]:https://www.linuxbabe.com/linux-server/install-git-verion-control-on-linux-debianubuntufedoraarchlinux#crt-2

View File

@ -0,0 +1,146 @@
Keep Accurate Time on Linux with NTP
======
![](https://www.linux.com/sites/lcom/files/styles/rendered_file/public/usno-amc.jpg?itok=KA8HwI02)
How to keep the correct time and keep your computers synchronized without abusing time servers, using NTP and systemd.
### What Time is It?
Linux is funky when it comes to telling the time. You might think that the `time` tells the time, but it doesn't because it is a timer that measures how long a process runs. To get the time, you run the `date` command, and to view more than one date, you use `cal`. Timestamps on files are also a source of confusion as they are typically displayed in two different ways, depending on your distro defaults. This example is from Ubuntu 16.04 LTS:
```
$ ls -l
drwxrwxr-x 5 carla carla 4096 Mar 27 2017 stuff
drwxrwxr-x 2 carla carla 4096 Dec 8 11:32 things
-rw-rw-r-- 1 carla carla 626052 Nov 21 12:07 fatpdf.pdf
-rw-rw-r-- 1 carla carla 2781 Apr 18 2017 oddlots.txt
```
Some display the year, some display the time, which makes ordering your files rather a mess. The GNU default is files dated within the last six months display the time instead of the year. I suppose there is a reason for this. If your Linux does this, try `ls -l --time-style=long-iso` to display the timestamps all the same way, sorted alphabetically. See [How to Change the Linux Date and Time: Simple Commands][1] to learn all manner of fascinating ways to manage the time on Linux.
### Check Current Settings
NTP, the network time protocol, is the old-fashioned way of keeping correct time on computers. `ntpd`, the NTP daemon, periodically queries a public time server and adjusts your system time as needed. It's a simple lightweight protocol that is easy to set up for basic use. Systemd has barged into NTP territory with the `systemd-timesyncd.service`, which acts as a client to `ntpd`.
Before messing with NTP, let's take a minute to check that current time settings are correct.
There are (at least) two timekeepers on your system: system time, which is managed by the Linux kernel, and the hardware clock on your motherboard, which is also called the real-time clock (RTC). When you enter your system BIOS, you see the hardware clock time and you can change its settings. When you install a new Linux, and in some graphical time managers, you are asked if you want your RTC set to the UTC (Coordinated Universal Time) zone. It should be set to UTC, because all time zone and daylight savings time calculations are based on UTC. Use the `hwclock` command to check:
```
$ sudo hwclock --debug
hwclock from util-linux 2.27.1
Using the /dev interface to the clock.
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2018/01/22 22:14:31
Hw clock time : 2018/01/22 22:14:31 = 1516659271 seconds since 1969
Time since last adjustment is 1516659271 seconds
Calculated Hardware Clock drift is 0.000000 seconds
Mon 22 Jan 2018 02:14:30 PM PST .202760 seconds
```
"Hardware clock is kept in UTC time" confirms that your RTC is on UTC, even though it translates the time to your local time. If it were set to local time it would report "Hardware clock is kept in local time."
You should have a `/etc/adjtime` file. If you don't, sync your RTC to system time:
```
$ sudo hwclock -w
```
This should generate the file, and the contents should look like this example:
```
$ cat /etc/adjtime
0.000000 1516661953 0.000000
1516661953
UTC
```
The new-fangled systemd way is to run `timedatectl`, which does not need root permissions:
```
$ timedatectl
Local time: Mon 2018-01-22 14:17:51 PST
Universal time: Mon 2018-01-22 22:17:51 UTC
RTC time: Mon 2018-01-22 22:17:51
Time zone: America/Los_Angeles (PST, -0800)
Network time on: yes
NTP synchronized: yes
RTC in local TZ: no
```
"RTC in local TZ: no" confirms that it is on UTC time. What if it is on local time? There are, as always, multiple ways to change it. The easy way is with a nice graphical configuration tool, like YaST in openSUSE. You can use `timedatectl`:
```
$ timedatectl set-local-rtc 0
```
Or edit `/etc/adjtime`, replacing UTC with LOCAL.
### systemd-timesyncd Client
Now I'm tired, and we've just gotten to the good part. Who knew timekeeping was so complex? We haven't even scratched the surface; read `man 8 hwclock` to get an idea of how time is kept on computers.
Systemd provides the `systemd-timesyncd.service` client, which queries remote time servers and adjusts your system time. Configure your servers in `/etc/systemd/timesyncd.conf`. Most Linux distributions provide a default configuration that points to time servers that they maintain, like Fedora:
```
[Time]
#NTP=
#FallbackNTP=0.fedora.pool.ntp.org 1.fedora.pool.ntp.org
```
You may enter any other servers you desire, such as your own local NTP server, on the `NTP=` line in a space-delimited list. (Remember to uncomment this line.) Anything you put on the `NTP=` line overrides the fallback.
What if you are not using systemd? Then you need only NTP.
### Setting up NTP Server and Client
It is a good practice to set up your own LAN NTP server, so that you are not pummeling public NTP servers from all of your computers. On most Linuxes NTP comes in the `ntp` package, and most of them provide `/etc/ntp.conf` to configure the service. Consult [NTP Pool Time Servers][2] to find the NTP server pool that is appropriate for your region. Then enter 4-5 servers in your `/etc/ntp.conf` file, with each server on its own line:
```
driftfile /var/ntp.drift
logfile /var/log/ntp.log
server 0.europe.pool.ntp.org
server 1.europe.pool.ntp.org
server 2.europe.pool.ntp.org
server 3.europe.pool.ntp.org
```
The `driftfile` tells `ntpd` where to store the information it needs to quickly synchronize your system clock with the time servers at startup, and your logs should have their own home instead of getting dumped into the syslog. Use your Linux distribution defaults for these files if it provides them.
Now start the daemon; on most Linuxes this is `sudo systemctl start ntpd`. Let it run for a few minutes, then check its status:
```
$ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================
+dev.smatwebdesi 192.168.194.89 3 u 25 64 37 92.456 -6.395 18.530
*chl.la 127.67.113.92 2 u 23 64 37 75.175 8.820 8.230
+four0.fairy.mat 35.73.197.144 2 u 22 64 37 116.272 -10.033 40.151
-195.21.152.161 195.66.241.2 2 u 27 64 37 107.559 1.822 27.346
```
I have no idea what any of that means, other than your daemon is talking to the remote time servers, and that is what you want. To permanently enable it, run `sudo systemctl enable ntpd`. If your Linux doesn't use systemd then it is your homework to figure out how to run `ntpd`.
Now you can set up `systemd-timesyncd` on your other LAN hosts to use your local NTP server, or install NTP on them and enter your local server in their `/etc/ntp.conf` files.
NTP servers take a beating, and demand continually increases. You can help by running your own public NTP server. Come back next week to learn how.
Learn more about Linux through the free ["Introduction to Linux" ][3]course from The Linux Foundation and edX.
--------------------------------------------------------------------------------
via: https://www.linux.com/learn/intro-to-linux/2018/1/keep-accurate-time-linux-ntp
作者:[CARLA SCHRODER][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.linux.com/users/cschroder
[1]:https://www.linux.com/learn/how-change-linux-date-and-time-simple-commands
[2]:http://support.ntp.org/bin/view/Servers/NTPPoolServers
[3]:https://training.linuxfoundation.org/linux-courses/system-administration-training/introduction-to-linux

View File

@ -0,0 +1,108 @@
Linux whereis Command Explained for Beginners (5 Examples)
======
Sometimes, while working on the command line, we just need to quickly find out the location of the binary file for a command. Yes, the [find][1] command is an option in this case, but it's a bit time consuming and will likely produce some non-desired results as well. There's a specific command that's designed for this purpose: **whereis**.
In this article, we will discuss the basics of this command using some easy to understand examples. But before we do that, it's worth mentioning that all examples in this tutorial have been tested on Ubuntu 16.04LTS.
### Linux whereis command
The whereis command lets users locate binary, source, and manual page files for a command. Following is its syntax:
```
whereis [options] [-BMS directory... -f] name...
```
And here's how the tool's man page explains it:
```
whereis locates the binary, source and manual files for the specified command names. The supplied
names are first stripped of leading pathname components and any (single) trailing extension of the
form .ext (for example: .c) Prefixes of s. resulting from use of source code control are also dealt
with. whereis then attempts to locate the desired program in the standard Linux places, and in the
places specified by $PATH and $MANPATH.
```
The following Q&A-styled examples should give you a good idea on how the whereis command works.
### Q1. How to find location of binary file using whereis?
Suppose you want to find the location for, let's say, the whereis command itself. Then here's how you can do that:
```
whereis whereis
```
[![How to find location of binary file using whereis][2]][3]
Note that the first path in the output is what you are looking for. The whereis command also produces paths for manual pages and source code (if available, which isn't in this case). So the second path you see in the output above is the path to the whereis manual file(s).
### Q2. How to specifically search for binaries, manuals, or source code?
If you want to search specifically for, say binary, then you can use the **-b** command line option. For example:
```
whereis -b cp
```
[![How to specifically search for binaries, manuals, or source code][4]][5]
Similarly, the **-m** and **-s** options are used in case you want to find manuals and sources.
### Q3. How to limit whereis search as per requirement?
By default whereis tries to find files from hard-coded paths, which are defined with glob patterns. However, if you want, you can limit the search using specific command line options. For example, if you want whereis to only search for binary files in /usr/bin, then you can do this using the **-B** command line option.
```
whereis -B /usr/bin/ -f cp
```
**Note** : Since you can pass multiple paths this way, the **-f** command line option terminates the directory list and signals the start of file names.
Similarly, if you want to limit manual or source searches, you can use the **-M** and **-S** command line options.
### Q4. How to see paths that whereis uses for search?
There's an option for this as well. Just run the command with **-l**.
```
whereis -l
```
Here is the list (partial) it produced for us:
[![How to see paths that whereis uses for search][6]][7]
### Q5. How to find command names with unusual entries?
For whereis, a command becomes unusual if it does not have just one entry of each explicitly requested type. For example, commands with no documentation available, or those with documentation in multiple places are considered unusual. The **-u** command line option, when used, makes whereis show the command names that have unusual entries.
For example, the following command should display files in the current directory which have no documentation file, or more than one.
```
whereis -m -u *
```
### Conclusion
Agreed, whereis is not the kind of command line tool that you'll require very frequently. But when the situation arises, it definitely makes your life easy. We've covered some of the important command line options the tool offers, so do practice them. For more info, head to its [man page][8].
--------------------------------------------------------------------------------
via: https://www.howtoforge.com/linux-whereis-command/
作者:[Himanshu Arora][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.howtoforge.com
[1]:https://www.howtoforge.com/tutorial/linux-find-command/
[2]:https://www.howtoforge.com/images/command-tutorial/whereis-basic-usage.png
[3]:https://www.howtoforge.com/images/command-tutorial/big/whereis-basic-usage.png
[4]:https://www.howtoforge.com/images/command-tutorial/whereis-b-option.png
[5]:https://www.howtoforge.com/images/command-tutorial/big/whereis-b-option.png
[6]:https://www.howtoforge.com/images/command-tutorial/whereis-l.png
[7]:https://www.howtoforge.com/images/command-tutorial/big/whereis-l.png
[8]:https://linux.die.net/man/1/whereis

View File

@ -0,0 +1,234 @@
#[闭包,对象,以及堆“族”][1]
在上篇文章中我们提到了闭包、对象、以及栈外的其它东西。我们学习的大部分内容都是与特定编程语言无关的元素,但是,我主要还是专注于 JavaScript以及一些 C。让我们以一个简单的 C 程序开始,它的功能是读取一首歌曲和乐队名字,然后将它们输出给用户:
stackFolly.c [下载][2]
```
#include <stdio.h>
#include <string.h>
char *read()
{
char data[64];
fgets(data, 64, stdin);
return data;
}
int main(int argc, char *argv[])
{
char *song, *band;
puts("Enter song, then band:");
song = read();
band = read();
printf("\n%sby %s", song, band);
return 0;
}
```
如果你运行这个程序,你会得到什么?(=> 表示程序输出):
```
./stackFolly
=> Enter song, then band:
The Past is a Grotesque Animal
of Montreal
=> ?ǿontreal
=> by ?ǿontreal
```
(曾经的 C 新手说)发生了错误?
事实证明,函数的栈变量的内容仅在栈帧活动期间才是可用的,也就是说,仅在函数返回之前。在上面的返回中,被栈帧使用的内存 [被认为是可用的][3],并且在下一个函数调用中可以被覆写。
下面的图展示了这种情况下究竟发生了什么。这个图现在有一个镜像映射,因此,你可以点击一个数据片断去看一下相关的 GDB 输出GDB 命令在 [这里][4])。只要 `read()` 读取了歌曲的名字,栈将是这个样子:
![](https://manybutfinite.com/img/stack/readSong.png)
在这个时候,这个 `song` 变量立即指向到歌曲的名字。不幸的是,存储字符串的内存位置准备被下次调用的任意函数的栈帧重用。在这种情况下,`read()` 再次被调用,而且使用的是同一个位置的栈帧,因此,结果变成下图的样子:
![](https://manybutfinite.com/img/stack/readBand.png)
乐队名字被读入到相同的内存位置,并且覆盖了前面存储的歌曲名字。`band` 和 `song` 最终都准确指向到相同点。最后,我们甚至都不能得到 “of Montreal”译者注一个欧美乐队的名字 的正确输出。你能猜到是为什么吗?
因此,即使栈很有用,但也有很重要的限制。它不能被一个函数用于去存储比该函数的运行周期还要长的数据。你必须将它交给 [堆][5],然后与热点缓存、明确的瞬时操作、以及频繁计算的偏移等内容道别。有利的一面是,它是[工作][6] 的:
![](https://manybutfinite.com/img/stack/readIntoHeap.png)
这个代价是你必须记得去`free()` 内存,或者由一个垃圾回收机制花费一些性能来随机回收,垃圾回收将去找到未使用的堆对象,然后去回收它们。那就是栈和堆之间在本质上的权衡:性能 vs. 灵活性。
大多数编程语言的虚拟机都有一个中间层用来做一个 C 程序员该做的一些事情。栈被用于**值类型**,比如,整数、浮点数、以及布尔型。这些都按特定值(像上面的 `argc` )的字节顺序被直接保存在本地变量和对象字段中。相比之下,堆被用于**引用类型**,比如,字符串和 [对象][7]。 变量和字段包含一个引用到这个对象的内存地址,像上面的 `song``band`
参考这个 JavaScript 函数:
```
function fn()
{
var a = 10;
var b = { name: 'foo', n: 10 };
}
```
它可能的结果如下:
![](https://manybutfinite.com/img/stack/fnFrame.png)
我之所以说“可能”的原因是,特定的行为高度依赖于实现。这篇文章使用的许多图形是以一个 V8 为中心的方法,这些图形都链接到相关的源代码。在 V8 中,仅 [小整数][8] 是 [以值的方式保存][9]。因此,从现在开始,我将在对象中直接以字符串去展示,以避免引起混乱,但是,请记住,正如上图所示的那样,它们在堆中是分开保存的。
现在,我们来看一下闭包,它其实很简单,但是由于我们将它宣传的过于夸张,以致于有点神化了。先看一个简单的 JS 函数:
```
function add(a, b)
{
var c = a + b;
return c;
}
```
这个函数定义了一个词法域lexical scope它是一个快乐的小王国在这里它的名字 abc 是有明确意义的。它有两个参数和由函数声明的一个本地变量。程序也可以在别的地方使用相同的名字,但是在 `add` 内部它们所引用的内容是明确的。尽管词法域是一个很好的术语,它符合我们直观上的理解:毕竟,我们从字面意义上看,我们可以像词法分析器一样,把它看作在源代码中的一个文本块。
在看到栈帧的操作之后,很容易想像出这个名称的具体实现。在 `add` 内部,这些名字引用到函数的每个运行实例中私有的栈的位置。这种情况在一个虚拟机中经常发生。
现在,我们来嵌套两个词法域:
```
function makeGreeter()
{
return function hi(name){
console.log('hi, ' + name);
}
}
var hi = makeGreeter();
hi('dear reader'); // prints "hi, dear reader"
```
那样更有趣。函数 `hi` 在函数 `makeGreeter` 运行的时候被构建在它内部。它有它自己的词法域,`name` 在这个地方是一个栈上的参数,但是,它似乎也可以访问父级的词法域,它可以那样做。我们来看一下那样做的好处:
```
function makeGreeter(greeting)
{
return function greet(name){
console.log(greeting + ', ' + name);
}
}
var heya = makeGreeter('HEYA');
heya('dear reader'); // prints "HEYA, dear reader"
```
虽然有点不习惯,但是很酷。即便这样违背了我们的直觉:`greeting` 确实看起来像一个栈变量,这种类型应该在 `makeGreeter()` 返回后消失。可是因为 `greet()` 一直保持工作,出现了一些奇怪的事情。进入闭包:
![](https://manybutfinite.com/img/stack/closure.png)
虚拟机分配一个对象去保存被里面的 `greet()` 使用的父级变量。它就好像是 `makeGreeter` 的词法作用域在那个时刻被关闭了,一旦需要时被具体化到一个堆对象(在这个案例中,是指返回的函数的生命周期)。因此叫做闭包,当你这样去想它的时候,它的名字就有意义了。如果使用(或者捕获)了更多的父级变量,对象内容将有更多的属性,每个捕获的变量有一个。当然,发送到 `greet()` 的代码知道从对象内容中去读取问候语,而不是从栈上。
这是完整的示例:
```
function makeGreeter(greetings)
{
var count = 0;
var greeter = {};
for (var i = 0; i < greetings.length; i++) {
var greeting = greetings[i];
greeter[greeting] = function(name){
count++;
console.log(greeting + ', ' + name);
}
}
greeter.count = function(){return count;}
return greeter;
}
var greeter = makeGreeter(["hi", "hello","howdy"])
greeter.hi('poppet');//prints "howdy, poppet"
greeter.hello('darling');// prints "howdy, darling"
greeter.count(); // returns 2
```
是的,`count()` 在工作,但是我们的 `greeter` 是在 `howdy` 中的栈上。你能告诉我为什么吗?我们使用 `count` 是一条线索:尽管词法域进入一个堆对象中被关闭,但是变量(或者对象属性)带的值仍然可能被改变。下图是我们拥有的内容:
![](https://manybutfinite.com/img/stack/greeterFail.png)
这是一个被所有函数共享的公共内容。那就是为什么 `count` 工作的原因。但是,`greeting` 也是被共享的并且它被设置为迭代结束后的最后一个值在这个案例中是“howdy”。这是一个很常见的一般错误避免它的简单方法是引用一个函数调用以闭包变量作为一个参数。在 CoffeeScript 中, [do][10] 命令提供了一个实现这种目的的简单方式。下面是对我们的 `greeter` 的一个简单的解决方案:
```
function makeGreeter(greetings)
{
var count = 0;
var greeter = {};
greetings.forEach(function(greeting){
greeter[greeting] = function(name){
count++;
console.log(greeting + ', ' + name);
}
});
greeter.count = function(){return count;}
return greeter;
}
var greeter = makeGreeter(["hi", "hello", "howdy"])
greeter.hi('poppet'); // prints "hi, poppet"
greeter.hello('darling'); // prints "hello, darling"
greeter.count(); // returns 2
```
它现在是工作的,并且结果将变成下图所示:
![](https://manybutfinite.com/img/stack/greeter.png)
这里有许多箭头!在这里我们感兴趣的特性是:在我们的代码中,我们闭包了两个嵌套的词法内容,并且完全可以确保我们得到了两个链接到堆上的对象内容。你可以嵌套并且闭包任何词法内容、“俄罗斯套娃”类型、并且最终从本质上说你使用的是所有那些对象内容的一个链表。
当然,就像受信鸽携带信息启发实现了 TCP 一样去实现这些编程语言的特性也有很多种方法。例如ES6 规范定义了 [词法环境][11] 作为 [环境记录][12]( 大致相当于在一个块内的本地标识)的组成部分,加上一个链接到外部环境的记录,这样就允许我们看到的嵌套。逻辑规则是由规范(一个希望)所确定的,但是其实现取决于将它们变成比特和字节的转换。
你也可以检查具体案例中由 V8 产生的汇编代码。[Vyacheslav Egorov][13] 有一篇很好的文章,它在细节中使用 V8 的 [闭包内部构件][14] 解释了这一过程。我刚开始学习 V8因此欢迎指教。如果你熟悉 C#,检查闭包产生的中间代码将会很受启发 - 你将看到显式定义的 V8 内容和实例化的模拟。
闭包是个强大的“家伙”。它在被一组函数共享期间,提供了一个简单的方式去隐藏来自调用者的信息。我喜欢它们真正地隐藏你的数据:不像对象字段,调用者并不能访问或者甚至是看到闭包变量。保持接口清晰而安全。
但是它们并不是“银弹”译者注意指极为有效的解决方案或者寄予厚望的新技术。有时候一个对象的拥护者和一个闭包的狂热者会无休止地争论它们的优点。就像大多数的技术讨论一样他们通常更关注的是自尊而不是真正的权衡。不管怎样Anton van Straaten 的这篇 [史诗级的公案][15] 解决了这个问题:
> 德高望重的老师 Qc Na 和它的学生 Anton 一起散步。Anton 希望将老师引入到一个讨论中Anton 说“老师我听说对象是一个非常好的东西是这样的吗Qc Na 同情地看了一眼,责备它的学生说:“可怜的孩子 - 对象不过是穷人的闭包。” Anton 待它的老师走了之后,回到他的房间,专心学习闭包。他认真地阅读了完整的 “LambdaThe Ultimate…" 系列文章和它的相关资料,并使用一个基于闭包的对象系统实现了一个小的架构解释器。他学到了很多的东西,并期待告诉老师他的进步。在又一次和 Qc Na 散步时Anton 尝试给老师留下一个好的印象说“老师我仔细研究了这个问题并且现在理解了对象真的是穷人的闭包。”Qc Na 用它的手杖打了一下 Anton 说“你什么时候才能明白闭包是穷人的对象。”在那个时候Anton 顿悟了。Anton van Straaten 说:“原来架构这么酷啊?”
探秘“栈”系列文章到此结束了。后面我将计划去写一些其它的编程语言实现的主题,像对象绑定和虚表。但是,内核调用是很强大的,因此,明天将发布一篇操作系统的文章。我邀请你 [订阅][16] 并 [关注我][17]。
--------------------------------------------------------------------------------
via:https://manybutfinite.com/post/closures-objects-heap/
作者:[Gustavo Duarte][a]
译者:[qhwdw](https://github.com/qhwdw)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://duartes.org/gustavo/blog/about/
[1]:https://manybutfinite.com/post/closures-objects-heap/
[2]:https://manybutfinite.com/code/x86-stack/stackFolly.c
[3]:https://manybutfinite.com/post/epilogues-canaries-buffer-overflows/
[4]:https://github.com/gduarte/blog/blob/master/code/x86-stack/stackFolly-gdb-commands.txt
[5]:https://github.com/gduarte/blog/blob/master/code/x86-stack/readIntoHeap.c
[6]:https://github.com/gduarte/blog/blob/master/code/x86-stack/readIntoHeap-gdb-output.txt#L47
[7]:https://code.google.com/p/v8/source/browse/trunk/src/objects.h#37
[8]:https://code.google.com/p/v8/source/browse/trunk/src/objects.h#1264
[9]:https://code.google.com/p/v8/source/browse/trunk/src/objects.h#148
[10]:http://coffeescript.org/#loops
[11]:http://people.mozilla.org/~jorendorff/es6-draft.html#sec-lexical-environments
[12]:http://people.mozilla.org/~jorendorff/es6-draft.html#sec-environment-records
[13]:http://mrale.ph
[14]:http://mrale.ph/blog/2012/09/23/grokking-v8-closures-for-fun.html
[15]:http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg03277.html
[16]:https://manybutfinite.com/feed.xml
[17]:http://twitter.com/manybutfinite

View File

@ -0,0 +1,292 @@
25本免费学习linux的书
======
简介: 在这篇文章中,我将与你分享**免费学习Linux**的最佳资源。这是一个网站,在线视频课程和免费电子书的集合。
**如何学习linux?**
这可能是 Facebook Linux 用户群组中最常见的问题。
'如何学习linux'这个看起来简单的问题的答案并不简单。
问题在于不同的人对于学习 linux 有不同的意义。
* 比如有人从来没有使用过 Linux无论是命令行还是桌面版本那个人可能只是想知道更多关于它的信息。
* 比如有人使用 Windows 作为桌面,但必须在工作中使用 Linux 命令行,那个人可能对学习 Linux 命令感兴趣。
* 比如有人已经使用过一段时间的 Linux而且懂得一些基础但他/她可能想要更上一层楼。
* 比如有人只是对 Linux 特定的发行版本感兴趣。
* 比如有人想要改进或学习几乎与 Linux 命令行差不多的Bash脚本。
* 比如有人想要从事一个 Linux 系统管理员的职业,或者想提高他/她的系统管理技能。
你看,'我如何学习Linux'的答案取决于你追求什么样的 linux 知识。为此我收集了大量能用来学习Linux的资源
这些免费的资源包括电子书,视频课程,网站等。这些资源分成几个子类别,以便当你试图学习 Linux 时可以很容易地找到你想要的东西。
再者,这里没有**最好的方式来学习Linux**。这完全取决于你如何去学习 Linux通过在线门户网站下载电子书视频课程或者其他。
让我们看看你能如何学习 Linux。
**免责声明** : 这里列举的所有书都可以合法的下载。 据我所知,这里提到的资源都是官方的资源。但是,如果你发现它不是,请让我知道以便我可以采取适当的措施。
![Best Free eBooks to learn Linux for Free][1]
## 1. 对于完全新手的免费资料
也许你刚刚从朋友那里或者从网上的讨论中听到了 Linux。关于 Linux 的炒作让你对Linux很感兴趣你被互联网上的大量信息所淹没不知道在哪里寻找更多的关于Linux的知识。
不用担心, 我们中的大多数, 即使不是全部, 已经来到你的身边
### Linux基金会关于Linux的介绍 [Video Course]
如果你对于什么是Linux和如何开始学习Linux完全没有概念的话我建议你从学习Linux基金会[Linux Foundation][2]在[edX][3]提供的免费的视频课程开始。
把它当做一个'维护'Linux组织的官方的课程。是的它是由Linux之父[Linus Torvalds][4]赞同的
[Introduction To Linux][5]
### Linux 旅程 [Online Portal]
不是官方的也许不是很受欢迎。但是这个小网站对于初学者来说是一个Linux学习的完美场所。
该网站设计精美,并根据主题组织得很好。它给你提供了能够在阅读完一个片段或章节后的进行的互动式测验。我的建议,收藏这个网站:
[Linux Journey][6]
### 5天学习Linux [eBook]
这本出色的书对于它专门的 FOSS 读者 来说完全的免费,这完全得感谢[Linux Training Academy][7]。
为了完全的新手而写,这本免费的 Linux 电子书给你一个关于 Linux的概述常用的 Linux指令和你开始学习 Linux 所需要的其他东西
你能够从下面的网页下载书:
[Learn Linux In 5 Days][8]
### 终极的Linux新手指南 [eBook]
这是一本Linux初学者可以免费下载的电子书。电子书从解释什么是 Linux 开始然后继续提供了更多Linux作为桌面的实际的使用。
您可以从下面的链接下载最新版本的电子书:
[The Ultimate Linux Newbie Guide][9]
## 2. 初学者进阶的免费书籍
本节列出了那些已经"完成"的 Linux 电子书。
我的意思是,这些之中的大部分就像是专注于 Linux 的每个方面的学术教科书。你可以作为一个绝对的新手阅读这些书或者你可以作为一个中级的 Linux 用户来深入学习。即使你已经是专家级,你也可以把它们作为参考
### Introduction to Linux [eBook]
Linux 简介是[The Linux Documentation Project][10]的免费电子书,而且它是最热门的 Linux 免费电子书之一。即使我认为其中的部分段落需要更新,它仍然是一本非常好的电子书来教你 LinuxLinux 的文件系统,命令行,网络和其他相关的东西。
[Introduction To Linux][11]
### Linux 基础 [eBook]
这本由 Paul Cobbaut 编写的免费的电子书教你关于 Linux 的历史,安装和你需要知道的基本的 Linux 命令。你能够从下列链接上得到这本书:
[Linux Fundamentals][12]
### 高级的 Linux 编程[eBook]
顾名思义,这是一本对于想要或者正在开发 Linux 软件的高级用户的书。它解决了负责的功能比如多进程,多线程,进程间通信以及和硬件设备的交互。
跟着这本书学习会帮你开发一个更快速,更可靠,更安全的使用 GNU/Linux 系统全部功能的项目
[Advanced Linux Programming][13]
### Linux From Scratch(就是一种从网上直接下载源码从头编译LINUX的安装方式) [eBook]
如果你认为自己对Linux有足够的了解并且你是一个专业人士那么为什么不创建自己的Linux版本呢 Linux From ScratchLFS是一个完全基于源代码为你构建你自定义的 Linux 系统提供手把手的指导。
把它叫做 DIY Linux 但是它是一个把你的 Linux 专业知识提高到新的高度的方法。
这里有许多的关于这个项目的子项目,你能够在这个网站上查看和下载。
[Linux From Scratch][14]
## 3.免费的电子书来学习 Linux 命令和 Shell脚本
Linux 的真正强大在于命令行,如果你想要征服 Linux你必须学习命令行和shell
事实上如果你必须在你的工作中使用Linux终端那么熟悉Linux命令行实际上会帮助你完成任务也有可能帮助你提高你的职业生涯因为你会更有效率
在本节中我们将看到各种Linux命令的免费电子书。
### GNU/Linux CommandLine Tools Summary [eBook]
这本Linux文档项目中的电子书是接触Linux命令行并开始熟悉Shell脚本的好地方
[GNU/Linux CommandLine Tools Summary][15]
### 来自 GNU 的 Bash 参考指南[eBook]
这是一本从[GNU][16]下载的免费电子书。 就像名字暗示的那样, 它涉及 Bash Shell (如果我能这么叫的话). 这本书有超过175页而且它包括了许多在 Bash里和 Linux有关的主题。
你能够从下面的链接中获取:
[Bash Reference Manual][17]
### Linux 命令行 [eBook]
这本500多页的由William Shotts编写的免费电子书对于那些认真学习Linux命令行的人来说是一本必须拥有的书。
即使你认为你知道关于Linux的东西你还是会惊讶于这本书能教你很多东西。
它涵盖了从初学者到高级的东西。我敢打赌读完这本书之后你会成为一个更好的Linux用户。请下载这本书并且随时携带它。
[The Linux Command Line][18]
### Bash 入门指南 [eBook]
如果你是想从 Bash 脚本开始,这可能对于你来说是一个很好的助手。 Linux 文档项目又是这本电子书的基础,它是编写 Linux 介绍的电子书的作者(本文前面讨论过)。
[Bash Guide for Beginners][19]
### 高级的 Bash 脚本指南[eBook]
如果你认为你已经知道了基本的Bash脚本的知识并且你想把你的技能提高到一个新的水平这本书就是你所需要的。这本书有超过900页的各种高级命令和举例。
[Advanced Bash-Scripting Guide][20]
### AWK 编程语言 [eBook]
这不是最漂亮的书,但是如果你真的想要通过脚本研究的更深,这本旧的但是依然发光的书会很有帮助。
[The AWK Programming Language][21]
### Linux 101 黑客 [eBook]
这本来自 "The Geek Stuf" 的书通过易于跟踪学习的例子教你基本的 Linux 命令行。你能够从下列的链接获取:
[Linux 101 Hacks][22]
## 4. 特定版本的免费学习资料
这个章节专注于特定 Linux 版本的材料。到目前为止,我们看到的都是常规的 Linux更多的关注文件系统命令和其他的核心内容。
这些书,在另一方面,可以被认为是用户手册或者开始学习各种各样的 Linux 版本的指南。所以如果你正在使用一个特定的 Linux 版本或者你准备使用它,你可以参考这些资源。是的,这些书更加关注 Linux 桌面。
我还想补充的是大部分的 Linux 版本有它们自己的大量的 wiki 或者文档。你能够从网上随时找到它们。
### Ubuntu 用户指南
不用说这本书是针对 Ubuntu 用户的。这是一个独立的项目在免费的电子书中提供 Ubuntun 的用户指南。它对于每个版本的 Ubuntu 都有更新。
这本书被叫做用户指南因为它是由一步步的指导组成而且受众目标是对于 Ubuntu 绝对的新手。所以,你会去了解 Unity 桌面,怎样慢慢走近而且查找应用等等。
如果你从来没有使用过 Ubuntu Unity 那么这是一本你必须拥有的书因为它帮助你理解怎样在日常中使用 Ubuntu。
[Ubuntu Manual][23]
### 对于 Linux Mint: 只要告诉我 Damnit! [eBook]
一本非常基本的关于 Linux Mint 的电子书。它告诉你怎么样在虚拟机中安装 Linux Mint怎么样去查找软件安装更新和自定义 Linux Mint 桌面。
你能够在下面的链接下载电子书:
[Just Tell Me Damnit!][24]
### Solus Linux 用户指南 [eBook]
注意!这本书过去是 Solus Linux 的官方用户指南但是我找不到 Solux 项目的网站上在哪里有提到它。我不知道它是不是已经过时了。尽管如此学习一点Solu Linux 并不是受到伤害,不是吗?
[Solus Linux User Guide][25]
## 5. 对于系统管理者的免费电子书
这个章节主要关注与系统管理者,开发者的超级英雄。我已经列了一部分会真正帮助那些已经是系统管理者或者想要成为系统管理者的免费的电子书。我必须补充你必须要关注基本的 Linux 命令行因为它会使你的工作更加简单
### The Debian 管理者的手册 [eBook]
如果你使用 Debian Linux 作为你的服务器,这本书就是你的圣经。这本书从 Debian 的历史,安装,包管理等等开始,接着覆盖一些主题,比如说[LAMP][26],虚拟机,存储管理和其他核心系统管理。
[The Debian Administration's Handbook][27]
### 高级的 Linux 系统管理者[eBook]
如果在准备[LPI certification][28],那么这本书是一本理想的书。这本书的涉及系统管理员必要的主题。所以了解 Linux 命令行在这个条件下是一个前置条件。
[Advanced Linux System Administration][29]
### Linux 系统管理者 [eBook]
Paul Cobbaut 编写的另一本免费的电子书。370页长的的书包括了网络磁盘管理用户管理内核管理库管理等等。
[Linux System Administration][30]
### Linux 服务器 [eBook]
又一本 Paul Cobbaut 编写的[linux-training.be][31]. 这本书包括了网页服务器mysqlDHCP,DNS,Samba和其他文件服务器。
[Linux Servers][32]
### Linux 网络 [eBook]
网络是系统管理者的面包和黄油,这本由 Paul Cobbaut 编写的书是一本好的参考资料。
[Linux Networking][33]
### Linux 存储 [eBook]
这本由 Paul Cobbaut(对,还是他) 编写的书解释了 Linux 的详细的磁盘管理而且介绍了许多其他的和存储相关的技术
[Linux Storage][34]
### Linux 安全 [eBook]
这是最后一本在这个书单里由 Paul Cobbaut 编写的书。 安全是系统管理员最重要的工作之一。这本书关注文件权限aclsSELinux用户和密码等等。
[Linux Security][35]
## 你最喜爱的 Linux 资料?
我知道这是一个免费 Linux 电子书的集合。但是它可以做的更好。
如果你有其他的在学习 Linux 有更大帮助的资料,请务必和我们共享。请注意只共享合法的下载资料以便我可以根据你的建议更新这篇文章而不会有任何问题。
我希望你觉得这篇文章在学习 Linux 时有帮助,欢迎你的反馈。
--------------------------------------------------------------------------------
via: https://itsfoss.com/learn-linux-for-free/
作者:[Abhishek Prakash][a]
译者:[yyyfor](https://github.com/yyyfor)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://itsfoss.com/author/abhishek/
[1]:https://4bds6hergc-flywheel.netdna-ssl.com/wp-content/uploads/2017/02/free-ebooks-linux-800x450.png
[2]:https://www.linuxfoundation.org/
[3]:https://www.edx.org
[4]:https://www.youtube.com/watch?v=eE-ovSOQK0Y
[5]:https://www.edx.org/course/introduction-linux-linuxfoundationx-lfs101x-0
[6]:https://linuxjourney.com/
[7]:https://www.linuxtrainingacademy.com/
[8]:https://courses.linuxtrainingacademy.com/itsfoss-ll5d/
[9]:https://linuxnewbieguide.org/ulngebook/
[10]:http://www.tldp.org/index.html
[11]:http://tldp.org/LDP/intro-linux/intro-linux.pdf
[12]:http://linux-training.be/linuxfun.pdf
[13]:http://advancedlinuxprogramming.com/alp-folder/advanced-linux-programming.pdf
[14]:http://www.linuxfromscratch.org/
[15]:http://tldp.org/LDP/GNU-Linux-Tools-Summary/GNU-Linux-Tools-Summary.pdf
[16]:https://www.gnu.org/home.en.html
[17]:https://www.gnu.org/software/bash/manual/bash.pdf
[18]:http://linuxcommand.org/tlcl.php
[19]:http://www.tldp.org/LDP/Bash-Beginners-Guide/Bash-Beginners-Guide.pdf
[20]:http://www.tldp.org/LDP/abs/abs-guide.pdf
[21]:https://ia802309.us.archive.org/25/items/pdfy-MgN0H1joIoDVoIC7/The_AWK_Programming_Language.pdf
[22]:http://www.thegeekstuff.com/linux-101-hacks-ebook/
[23]:https://ubuntu-manual.org/
[24]:http://downtoearthlinux.com/resources/just-tell-me-damnit/
[25]:https://drive.google.com/file/d/0B5Ymf8oYXx-PWTVJR0pmM3daZUE/view
[26]:https://en.wikipedia.org/wiki/LAMP_(software_bundle)
[27]:https://debian-handbook.info/about-the-book/
[28]:https://www.lpi.org/our-certifications/getting-started
[29]:http://www.nongnu.org/lpi-manuals/manual/pdf/GNU-FDL-OO-LPI-201-0.1.pdf
[30]:http://linux-training.be/linuxsys.pdf
[31]:http://linux-training.be/
[32]:http://linux-training.be/linuxsrv.pdf
[33]:http://linux-training.be/linuxnet.pdf
[34]:http://linux-training.be/linuxsto.pdf
[35]:http://linux-training.be/linuxsec.pdf

View File

@ -0,0 +1,135 @@
使用 TLS 加密保护 VNC 服务器的简单指南
======
在本教程中,我们将学习使用 TLS 加密安装 VNC 服务器并保护 VNC 会话。
此方法已经在 CentOS 67 上测试过了,但是也可以在其他的版本/操作系统上运行RHEL、Scientific Linux 等)。
**(推荐阅读:[保护 SSH 会话终极指南][1]**
### 安装 VNC 服务器
在机器上安装 VNC 服务器之前,请确保我们有一个可用的 GUI。如果机器上还没有安装 GUI我们可以通过执行以下命令来安装
```
yum groupinstall "GNOME Desktop"
```
现在我们将 tigervnc 作为我们的 VNC 服务器,运行下面的命令运行:
```
# yum install tigervnc-server
```
安装完成后,我们将创建一个新的用户访问服务器:
```
# useradd vncuser
```
并使用以下命令为其分配访问 VNC 的密码:
```
# vncpasswd vncuser
```
我们在 CentOS 6&7 上配置会有一点改变,我们首先看 CentOS 6 的配置。
#### CentOS 6
现在我们需要编辑 VNC 配置文件:
```
**# vim /etc/sysconfig/vncservers**
```
并添加下面这几行:
```
[ …]
VNCSERVERS= "1:vncuser"
VNCSERVERARGS[1]= "-geometry 1024×768″
```
保存文件并退出。接下来重启 vnc 服务使改动生效:
```
# service vncserver restart
```
并在启动时启用它:
```
# chkconfig vncserver on
```
#### CentOS 7
在 CentOS 7 上,/etc/sysconfig/vncservers 已经改为 /lib/systemd/system/vncserver@.service。我们将使用这个配置文件作为参考所以创建一个文件的副本
```
# cp /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@:1.service
```
接下来,我们将编辑文件以包含我们创建的用户:
```
# vim /etc/systemd/system/vncserver@:1.service
```
编辑下面 2 行中的用户:
```
ExecStart=/sbin/runuser -l vncuser -c "/usr/bin/vncserver %i"
PIDFile=/home/vncuser/.vnc/%H%i.pid
```
保存文件并退出。接下来重启服务并在启动时启用它:
```
systemctl restart[[email protected]][2]:1.service
systemctl enable[[email protected]][2]:1.service
```
现在我们已经设置好了 VNC 服务器,并且可以使用 VNC 服务器的 IP 地址从客户机连接到它。但是,在此之前,我们将使用 TLS 加密保护我们的连接。
### 保护 VNC 会话
要保护 VNC 会话,我们将首先配置加密方法。我们将使用 TLS 加密,但也可以使用 SSL 加密。执行以下命令在 VNC 服务器上使用 TLS 加密:
```
# vncserver -SecurityTypes=VeNCrypt,TLSVnc
```
你将被要求输入密码来访问 VNC如果使用其他用户而不是上述用户
![secure vnc server][4]
现在,我们可以使用客户机上的 VNC 浏览器访问服务器,使用以下命令以安全连接启动 vnc 浏览器:
**# vncviewer -SecurityTypes=VeNCrypt,TLSVnc 192.168.1.45:1**
这里192.168.1.45 是 VNC 服务器的 IP 地址。
![secure vnc server][6]
输入密码,我们可以远程访问服务器,并且也是 TLS 加密的。
这篇教程就完了,欢迎随时使用下面的评论栏提交你的建议或疑问。
--------------------------------------------------------------------------------
via: http://linuxtechlab.com/secure-vnc-server-tls-encryption/
作者:[Shusain][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linuxtechlab.com/author/shsuain/
[1]:http://linuxtechlab.com/ultimate-guide-to-securing-ssh-sessions/
[2]:/cdn-cgi/l/email-protection
[3]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=642%2C241
[4]:https://i1.wp.com/linuxtechlab.com/wp-content/uploads/2017/10/secure_vnc-1.png?resize=642%2C241
[5]:https://i1.wp.com/linuxtechlab.com/wp-content/plugins/a3-lazy-load/assets/images/lazy_placeholder.gif?resize=665%2C419
[6]:https://i2.wp.com/linuxtechlab.com/wp-content/uploads/2017/10/secure_vnc-2.png?resize=665%2C419

View File

@ -0,0 +1,129 @@
如何使用 CGI 脚本生成网页
======
回到互联网的开端,当我第一次创建了我的第一个商业网站,生活是无比的美好。
我安装 Apache 并写了一些简单的 HTML 网页,网页上列出了一些关于我的业务的重要信息,比如产品概览以及如何联系我。这是一个静态网站,因为内容很少改变。由于网站的内容很少改变这一性质,因此维护起来也很简单。
## 静态内容
静态内容很简单,同时也很常见。让我们快速的浏览一些静态网页的例子。你不需要一个可运行网站来执行这些小实验,只需要把这些文件放到 home 目录,然后使用浏览器打开。你所看到的内容将和通过 web 服务器提供这一文件看到的内容一样。
对于一个静态网站,你需要的第一件东西就是 index.html 文件,该文件通常放置在 `/var/www/html` 目录下。这个文件的内容可以非常简单,比如可以是像 "Hello, world" 这样一句短文本,没有任何 HTML 标记。它将简单的展示文本串内容。在你的 home 目录创建 index.html 文件,并添加 "hello, world" 作为内容(不需要引号)。在浏览器中通过下面的链接来打开这一文件:
```
file:///home/<yourhomedirectory>/index.html
```
所以 HTML 不是必须的,但是,如果你有大量需要格式化的文本,那么,不用 HTML 编码的网页的结果将会令人难以理解。
所以,下一步就是通过使用一些 HTML 编码来提供格式化,从而使内容更加可读。下面这一命令创建了一个具有 HTML 静态网页所需要的绝对最小标记的页面。你也可以使用你最喜欢的编辑器来创建这一内容。
```
echo "<h1>Hello World</h1>" > test1.html
```
现在,再次查看 index.html 文件,将会看到和刚才有些不同。
当然,你可以在实际的内容行上添加大量的 HTML 标记,以形成更加完整和标准的网页。下面展示的是更加完整的版本,尽管在浏览器中会看到同样的内容,但这也为更加标准化的网站奠定了基础。继续在 index.html 中写入这些内容并通过浏览器查看。
```
<!DOCTYPE HTML PUBLIC "-//w3c//DD HTML 4.0//EN">
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
```
我使用这些技术搭建了一些静态网站,但我的生活正在改变。
## 动态网页
我找了一份新工作,这份工作的主要任务就是创建并维护用于一个动态网站的 CGI[公共网关接口][6])代码。字面意思来看,动态意味着在浏览器中生成的网页所需要的 HTML 是由每次访问页面时所访问到的数据生成的。这些数据包括网页表格中的用户输入,以用来在数据库中进行数据查找,结果数据被一些恰当的 HTML 包围着并展示在所请求的浏览器中。但是这不需要非常复杂。
通过使用 CGI 脚本,你可以创建一些简单或复杂的交互式程序,通过运行这些程序能够生成基于输入、计算、服务器的当前条件等改变的动态页面。有许多种语言可以用来写 CGI 脚本,在这篇文章中,我将谈到的是 Perl 和 Bash ,其他非常受欢迎的 CGI 语言包括 PHP 和 Python 。
这篇文章不会介绍 Apache 或其他任何 web 服务器的安装和配置。如果你能够访问一个你可以进行实验的 web 服务器,那么你可以直接查看它们在浏览器中出现的结果。否则,你可以在命令行中运行程序来查看它们所创建的 HTML 文本。你也可以重定向 HTML 输出到一个文件中,然后通过浏览器查看结果文件。
### 使用 Perl
Perl 是一门非常受欢迎的 CGI 脚本语言,它的优势是强大的文本操作能力。
为了使 CGI 脚本可执行,你需要在你的网站的 httpd.conf 中添加下面这行内容。这会告诉服务器可执行 CGI 文件的位置。在这次实验中,不必担心这个问题。
```
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
```
把下面的 Perl 代码添加到文件 index.cgi在这次实验中这个文件应该放在你的 home 目录下。如果你使用 web 服务器,那么应把文件的所有者更改为 apache.apache同时将文件权限设置为 755因为无论位于哪它必须是可执行的。
```
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><body>\n";
print "<h1>Hello World</h1>\n";
print "Using Perl<p>\n";
print "</body></html>\n";
```
在命令行中运行这个程序并查看结果,它将会展示出它所生成的 HTML 内容
现在,在浏览器中查看 index.cgi 文件,你所看到的只是文件的内容。浏览器的确将它看做 CGI 内容但是Apache 不知道需要将这个文件作为 CGI 程序运行,除非 Apache 的配置中包括上面所展示的 "ScriptAlias" 定义。没有这一配置Apache 只会简单地将文件中的数据发送给浏览器。如果你能够访问 web 服务器,那么你可以将可执行文件放到 `/var/www/cgi-bin` 目录下。
如果想知道这个脚本的运行结果在浏览器中长什么样,那么,重新运行程序并把输出重定向到一个新文件,名字可以是任何你想要的。然后使用浏览器来查看这一文件,它包含了脚本所生成的内容。
上面这个 CGI 程序依旧生成静态内容,因为它总是生成相同的输出。把下面这行内容添加到 CGI 程序中 "Hello, world" 这一行后面。Perl 的 "system" 命令将会执行跟在它后面的 shell 命令,并把结果返回给程序。此时,我们将会通过 `free` 命令获得当前的 RAM 使用量。
```
system "free | grep Mem\n";
```
现在,重新运行这个程序,并把结果重定向到一个文件,在浏览器中重新加载这个文件。你将会看到额外的一行,它展示了系统的内存统计数据。多次运行程序并刷新浏览器,你将会发现,内存使用量应该是不断变化的。
### 使用 Bash
Bash 可能是用于 CGI 脚本中最简单的语言。用 Bash 来进行 CGI 编程的最大优势是它能够直接访问所有的标准 GNU 工具和系统程序。
把已经存在的 index.cgi 文件重命名为 Perl.index.cgi ,然后创建一个新的 index.cgi 文件并添加下面这些内容。记得设置权限使它可执行。
```
#!/bin/bash
echo "Content-type: text/html"
echo ""
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>Hello World</title>'
echo '</head>'
echo '<body>'
echo '<h1>Hello World</h1><p>'
echo 'Using Bash<p>'
free | grep Mem
echo '</body>'
echo '</html>'
exit 0
```
在命令行中执行这个文件并查看输出,然后再次运行并把结果重定向到一个临时结果文件中。然后,刷新浏览器查看它所展示的网页是什么样子。
## 结论
创建能够生成许多种动态网页的 CGI 程序实际上非常简单。尽管这是一个很简单的例子,但是现在你应该看到一些可能性了。
--------------------------------------------------------------------------------
via: https://opensource.com/article/17/12/cgi-scripts
作者:[David Both][a]
译者:[ucasFL](https://github.com/ucasFL)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://opensource.com/users/dboth
[1]:http://december.com/html/4/element/html.html
[2]:http://december.com/html/4/element/head.html
[3]:http://december.com/html/4/element/title.html
[4]:http://december.com/html/4/element/body.html
[5]:http://december.com/html/4/element/h1.html
[6]:https://en.wikipedia.org/wiki/Common_Gateway_Interface
[7]:http://perldoc.perl.org/functions/system.html

View File

@ -0,0 +1,132 @@
为初学者介绍的 Linux tee 命令6 个例子)
======
有时候你会想手动跟踪命令的输出内容同时又想将输出的内容写入文件确保之后可以用来参考。如果你想寻找这相关的工具那么恭喜你Linux 已经有了一个叫做 **tee** 的命令可以帮助你。
本教程中,我们将基于 tee 命令,用一些简单的例子开始讨论。但是在此之前,值得一提的是,本文我们所有的测试实例都基于 Ubuntu 16.04 LTS。
### Linux tee 命令
tee 命令基于标准输入读取数据,标准输出或文件写入数据。感受下这个命令的语法:
```
tee [OPTION]... [FILE]...
```
这里是帮助文档的说明:
```
从标准输入中复制到每一个文件,并输出到标准输出。
```
让 Q&A&答)风格的实例给我们带来更多灵感,深入了解这个命令。
### Q1. 如何在 Linux 上使用这个命令?
假设因为某些原因,你正在使用 ping 命令。
```
ping google.com
```
[![如何在 Linux 上使用 tee 命令][1]][2]
然后同时你想要输出的信息也同时能写入文件。这个时候tee 命令就有其用武之地了。
```
ping google.com | tee output.txt
```
下面的截图展示了这个输出内容不仅被写入 output.txt 文件,也被显示在标准输出中。
[![tee command 输出][3]][4]
如此应当明确了 tee 的基础用法。
### Q2. 如何确保 tee 命令追加信息到文件中?
默认情况下,在同一个文件下再次使用 tee 命令会覆盖之前的信息。如果你想的话,可以通过 -a 命令选项改变默认设置。
```
[command] | tee -a [file]
```
基本上,-a 选项强制 tee 命令追加信息到文件。
### Q3. 如何让 tee 写入多个文件?
这非常之简单。你仅仅只需要写明文件名即可。
```
[command] | tee [file1] [file2] [file3]
```
比如:
```
ping google.com | tee output1.txt output2.txt output3.txt
```
[![如何让 tee 写入多个文件][5]][6]
### Q4. 如何让 tee 命令的输出内容直接作为另一个命令的输入内容?
使用 tee 命令你不仅可以将输出内容写入文件还可以把输出内容作为另一个命令的输入内容。比如说下面的命令不仅会将文件名存入output.txt文件中还会通过 wc 命令让你知道输入到 output.txt 中的文件数目。
```
ls file* | tee output.txt | wc -l
```
[![如何让 tee 命令的输出内容直接作为另一个命令的输入内容][7]][8]
### Q5. 如何使用 tee 命令提升文件写入权限?
假如你使用 [Vim editor][9] 打开文件,并且做了很多更改,然后当你尝试保存修改时,你得到一个报错,让你意识到那是一个 root 所拥有的文件,这意味着你需要使用 sudo 权限保存修改。
[![如何使用 tee 命令提升文件写入权限][10]][11]
如此情况下,你可以使用 tee 命令来提高权限。
```
:w !sudo tee %
```
上述命令会向你索要 root 密码,然后就能让你保存修改了。
### Q6. 如何让 tee 命令忽视中断?
-i 命令行选项使 tee 命令忽视通常由 crl+c 组合键发起的中断信号(`SIGINT`)。
```
[command] | tee -i [file]
```
当你想要使用 crl+c 中断命令的同时,让 tee 命令优雅的退出,这个选项尤为实用。
### 总结
现在你可能已经认同 tee 是一个非常实用的命令。基于 tee 命令的用法,我们已经介绍了其绝大多数的命令行选项。这个工具并没有什么陡峭的学习曲线,所以,只需跟随这几个例子练习,你就可以运用自如了。更多信息,请查看 [帮助文档][12].
--------------------------------------------------------------------------------
via: https://www.howtoforge.com/linux-tee-command/
作者:[Himanshu Arora][a]
译者:[CYLeft](https://github.com/CYLeft)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.howtoforge.com
[1]:https://www.howtoforge.com/images/command-tutorial/ping-example.png
[2]:https://www.howtoforge.com/images/command-tutorial/big/ping-example.png
[3]:https://www.howtoforge.com/images/command-tutorial/ping-with-tee.png
[4]:https://www.howtoforge.com/images/command-tutorial/big/ping-with-tee.png
[5]:https://www.howtoforge.com/images/command-tutorial/tee-mult-files1.png
[6]:https://www.howtoforge.com/images/command-tutorial/big/tee-mult-files1.png
[7]:https://www.howtoforge.com/images/command-tutorial/tee-redirect-output.png
[8]:https://www.howtoforge.com/images/command-tutorial/big/tee-redirect-output.png
[9]:https://www.howtoforge.com/vim-basics
[10]:https://www.howtoforge.com/images/command-tutorial/vim-write-error.png
[11]:https://www.howtoforge.com/images/command-tutorial/big/vim-write-error.png
[12]:https://linux.die.net/man/1/tee

View File

@ -0,0 +1,95 @@
Linux mkdir 命令的初学者教程
======
当你使用命令行的时候,无论什么时候,你都位于一个目录中,它告诉了命令行当前所位于的完整目录。在 Linux 中,你可以使用 `rm` 命令删除目录,但是首先,你需要使用 `mkdir` 命令来创建目录。在这篇教程中,我将使用一些易于理解的例子来讲解这个工具的基本用法。
在开始之前,值得一提的是,这篇教程中的所有例子都已经在 Ubuntu 16.04 LTS 中测试过。
### Linux `mkdir` 命令
正如上面所提到的,用户可以使用 `mkdir` 命令来创建目录。它的语法如下:
```
mkdir [OPTION]... DIRECTORY...
```
下面的内容是 man 手册对这个工具的描述:
```
Create the DIRECTORY(ies), if they do not already exist.
```
下面这些问答式的例子将能够帮助你更好的理解 `mkdir` 这个命令是如何工作的。
### Q1. 如何使用 `mkdir` 命令创建目录?
创建目录非常简单,你唯一需要做的就是把你想创建的目录的名字跟在 `mkdir` 命令的后面作为参数。
```
mkdir [dir-name]
```
下面是一个简单例子:
```
mkdir test-dir
```
### Q2. 如何确保当父目录不存在的时候,同时创建父目录?
有时候,我们需要使用一条 `mkdir` 命令来创建一个完整的目录结构,这时候,你只需要使用 `-p` 这个命令行选项即可。
比如,你想创建目录 `dir1/dir2/dir3`,但是,该目录的父目录都不存在,这时候,你可以像下面这样做:
```
mkdir -p dir1/dir2/dir3
```
[![How to make sure parent directories \(if non-existent\) are created][1]][2]
### Q3. 如何在创建目录时自定义权限?
默认情况下,`mkdir` 命令创建目录时会把权限设置为 `rwx, rwx, r-x`
[![How to set permissions for directory being created][3]][4]
但是,如果你想自定义权限,那么你可以使用 `-m` 这一命令行选项。
[![mkdir -m command option][5]][6]
### Q4. 如何使 `mkdir` 命令显示操作细节?
如果你希望 `mkdir` 命令显示它所执行的操作的完整细节,那么你可以使用 `-v` 这一命令行选项。
```
mkdir -v [dir]
```
下面是一个例子:
[![How to make mkdir emit details of operation][7]][8]
### 结论
你已经看到,`mkdir` 是一个非常简单,易于理解和使用的命令。学习这一命令不会遇到任何屏障。在这篇教程中,我们讨论到了它的绝大部分命令行选项。记得练习这些命令,并在日复一日的工作中使用这些命令。如果你想了解关于这一命令的更过内容,请查看它的 [man][9] 手册。
--------------------------------------------------------------------------------
via: https://www.howtoforge.com/linux-mkdir-command/
作者:[Himanshu Arora][a]
译者:[ucasFL](https://github.com/ucasFL)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://www.howtoforge.com
[1]:https://www.howtoforge.com/images/command-tutorial/mkdir-p.png
[2]:https://www.howtoforge.com/images/command-tutorial/big/mkdir-p.png
[3]:https://www.howtoforge.com/images/command-tutorial/mkdir-def-perm.png
[4]:https://www.howtoforge.com/images/command-tutorial/big/mkdir-def-perm.png
[5]:https://www.howtoforge.com/images/command-tutorial/mkdir-custom-perm.png
[6]:https://www.howtoforge.com/images/command-tutorial/big/mkdir-custom-perm.png
[7]:https://www.howtoforge.com/images/command-tutorial/mkdir-verbose.png
[8]:https://www.howtoforge.com/images/command-tutorial/big/mkdir-verbose.png
[9]:https://linux.die.net/man/1/mkdir