linux-knowledgebase's Introduction
linux-knowledgebase's People
linux-knowledgebase's Issues
Command line
Table of contents generated with markdown-toc
ls
ls -a
: list all files including hidden files.
ls -l
or ls -la
: list all files and their permission info, etc.
ls -lh
display the size in a human-readable way
grep
grep -r "xxx" .
: search string "xxx" under current directory.
Redirection
Redirection (link)
redirect the output to a file:
SomeCommand > SomeFile.txt
Or if you want to append data:
SomeCommand >> SomeFile.txt
If you want stderr as well use this:
SomeCommand &> SomeFile.txt
or this to append:
SomeCommand &>> SomeFile.txt
if you want to have both stderr and output displayed on the console and in a file use this:
SomeCommand 2>&1 | tee SomeFile.txt
(If you want the output only, drop the 2 above)
mkdir
mkdir -p aa/bb/cc
'-p' guarantees the dirs along the path can be created if it doesn't exist.
Without '-p', if you use "mkdir aa/bb/cc" while there is not aa dir or bb dir, an error would be posted and cc dir can not be created.
Linux User Management
Linux Users and groups
Create a new user and set its password:
#You need to apply the commands with root permission( with sudo
or using sudo su -
to switch to root account ) most of the time.
useradd newusername
passwd newuser'spassword
To verify new user is successfully created:
su newusername
switch to the new user account, type corresponding password. If you login, then it successes! To log in back to original account, you can just useexit
command.
Once a new user created, it entry is added to /etc/passwd
file like:
newusername:x:1001:1001::/home/newusername:
Username:Password:UserID(UID):GroupID(GID):UserInfo:HomeDirectory:Shell
What are these fields:
- Username: User login name used to login into system. It should be between 1 to 32 charcters long.
Password: User password (or x character) stored in /etc/shadow file in encrypted format. - User ID (UID): Every user must have a User ID (UID) User Identification Number. By default UID 0 is reserved for root user and - - UID’s ranging from 1-99 are reserved for other predefined accounts. Further UID’s ranging from 100-999 are reserved for system accounts and groups.
- Group ID (GID): The primary Group ID (GID) Group Identification Number stored in /etc/group file.
- User Info: This field is optional and allow you to define extra information about the user. For example, user full name. This field is filled by ‘finger’ command.
- Home Directory: The absolute location of user’s home directory.
- Shell: The absolute location of a user’s shell i.e. /bin/bash.
Add home directory for new user:
useradd -d /home/HomeDirectoryName newusername
Change the ownership of dirs or files:
chown newusername -R a/b/c/
means giving newusername the ownship of directory a/b/c/ and all files inside it.
chown newusername a/b/c/
means giving newusername the ownship of directory a/b/c/.
Created a new group
groupadd newgroupname
.
Groups information is stored in /etc/group
Change the group ownership of a file or directories.
chgrp [-R] groupname fileORdirectory
-R option means to change the group ownership recursively of files and directories.
You can also pass multiple files to chgrp command as arguments:
chgrp groupname file1 file2 file3
Reference:
https://www.tecmint.com/add-users-in-linux/
ssh to remote linux server without password
Ref: https://netbeez.net/blog/connect-to-ssh-without-password/
-
Generate a private, public key pair
-
Copy the public key to the remote server: append it to
.ssh/authorized_keys
ifauthorized_keys
file doesn't exist, create one.cat .ssh/id_rsa.pub | ssh user_name@destination ‘cat >> .ssh/authorized_keys’
-
You are all set.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.