PDA

View Full Version : Tips and useful Linux commands dump


Anthem
January 1st, 2016, 07:32 AM
Commands that I use on my CentOS server

Share your useful hax/commands here! Any OS welcome!


Useful Linux Commands

Rights Management

Adds rights to all the users on the system to all the files and folders in the specified folder:
>sudo chmod -R ugo+rw /foo/bar

----------------------------------------------------------------------------------------------------------------------------------------------------
Harden Linux

Disable root login:
>sudo vi /etc/ssh/sshd_config

Locate the line:
#PermitRootLogin yes

Press INSERT

Change it to:
PermitRootLogin no

Press escape, then type
>:wq
To save and quit
w: write
q: quit
--------------------------------------------------------------------------------------------------------------------------------------------------
Potential Useful Commands In Emergency Crisis

Get all the users logged-in to the system:
>w

Log a user out of their session:
>pkill -KILL -u username

Changing a user(s) password
>passwd user

Modifying the sudo user(s)
>sudo visudo

Show all running processes (and who is running it)
>ps aux | less

<- and -> to scroll

And to quit:
>q

And if all else fails:
>shutdown -h now

That will shut down the system as soon as you type the command

And to prevent mishaps, please log out:
>logout

That will close the terminal and the session.
----------------------------------------------------------------------------------------------------------------------------------------------------
Useful info for a server move (or just for having backups sake)

Exporting a database:
>mysqldump -p database_name > /path/to/file.sql

Importing a database:
First, we need to create the desired database we are going to import:
>CREATE DATABASE dbname
Then, do this:
>exit;
Then, we can import:
>mysql -p dbname < /path/to/file.sql
Type in the MySQL password and it will import

Create a MySQL user:
>CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
Then, we have to grant permissions to the user (you can set for all dbs, but i want the website to only have some permissions)
>GRANT permission ON db.table TO 'username'@'localhost';
Type of permissions that can be granted (copypasta):

ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
CREATE- allows them to create new tables or databases
DROP- allows them to them to delete tables or databases
DELETE- allows them to delete rows from tables
INSERT- allows them to insert rows into tables
SELECT- allows them to use the Select command to read through databases
UPDATE- allow them to update table rows
GRANT OPTION- allows them to grant or remove other users' privileges

Typhlosion
January 1st, 2016, 08:55 AM
>shutdown now

And boot into Windows instead :P

Anthem
January 1st, 2016, 09:47 AM
>shutdown now

And boot into Windows instead :P

I use CentOS on my server, I can't install windows because I would need to crack it plus, my host doesn't allow for custom images!

D'oh!

northy
January 1st, 2016, 01:00 PM
Touch - update a file, create a file or change the timestamps on a file. I use it in my CI script.

phuckphace
January 1st, 2016, 01:05 PM
sudo apt-get install Windows

northy
January 1st, 2016, 01:28 PM
sudo apt-get install Windows
Sudo apt-get purge Windows

. /phuckface | /dev/null

phuckphace
January 1st, 2016, 10:16 PM
Sudo apt-get purge Windows

. /phuckface | /dev/null

say not in grief "he is no more", but live in thankfulness that he was