-
Notifications
You must be signed in to change notification settings - Fork 1
System
Answer
/etc/debian_version
Answer
hostname new_name
Explanation
man hostname:
Hostname is used to display the system's DNS name, and to display or set its hostname or NIS domain name.
Answer
/etc/hostname
Answer
uptime
Explanation
man uptime:
uptime gives a one line display of the following information. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.
Answer
service ssh status
Tip
Install SSH server:
apt-get install openssh-server
Answer
service ssh restart
Answer
cat /var/run/sshd.pid
Answer
~/.ssh/authorized_keys
Explanation
The file contains public keys for public key authentication.
Answer
who
Explanation
man who:
Print information about users who are currently logged in.
Answer
fdisk -l
Explanation
man fdisk:
-l,--list— List the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that exists) are used.
Answer
df -h --total
Explanation
man df:
df— report file system disk space usage.
-h,--human-readable— Print sizes in powers of 1024 (e.g., 1023M).
--total— Elide all entries insignificant to available space, and produce a grand total.
Answer
du -sh /var/*
Explanation
du— estimate file space usage.
Summarize disk usage of each FILE, recursively for directories.
-s,--summarize— Display only a total for each argument.
-h,--human-readable— Print sizes in human readable format (e.g., 1K 234M 2G).
Alternative answers
du -hd0 /var/*
du -h --max-depth=0 /var/*
Explanation
-d,--max-depth=N— Print the total for a directory (or file, with--all) only if it is N or fewer levels below the command line argument;--max-depth=0is the same as--summarize.
Answer
ps aux
Answer
tail -f /var/log/syslog &
Explanation
Running Bash Commands in the Background the Right Way [Linux]:
If you want to push a command into the background, using & at the end is an easy way to do that. It comes with a catch, though. Using & doesn’t disconnect the command away from you; it just pushes it in the background so you can continue using a terminal.
command &When the terminal session is closed, the command ends. Using & is good if you need to push something off for a bit, but don’t expect it to continue forever.
Answer
pkill tail
Explanation
The pkill command allows to kill a program by specifying the full name or partial name.
Alternative answer
kill %<job number>
Explanation
Instead of <job number> we need to place job number of process, which we want to kill.
Alternative answer
kill <PID>
Explanation
How do I run a Unix process in the background?:
You can kill a background process by entering:
kill PIDReplace PID with the process ID of the job. If that fails, enter the following:
kill -KILL PID
The command kill sends the specified signal to the specified process or process group. If no signal is specified, the TERM signal is sent. The TERM signal will kill processes which do not catch this signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot be caught.
If we want to do it this way, first of all we need to know PID of process. jobs -l will help us.
Linux 2.6 - man page for jobs (linux section 1):
jobs— display status of jobs in the current session.
-l— Provide more information about each job listed. This information shall include the job number, current job, process group ID, state, and the command that formed the job.
Answer
cron
Explanation
man cron:
cron— daemon to execute scheduled commands.
Answer
iptables -L
Note
You must be root to run this command.
Explanation
iptables— administration tool for IPv4 packet filtering and NAT.
-L,--list [chain]— List all rules in the selected chain. If no chain is selected, all chains are listed.
18. With the previous command, authorize only IP addresses from 10.0.0.0/8 to connect to your system.
Types of chains
The Beginner’s Guide to iptables, the Linux Firewall:
iptablesuses three different chains: input, forward, and output.
Input – This chain is used to control the behavior for incoming connections. For example, if a user attempts to SSH into your PC/server,
iptableswill attempt to match the IP address and port to a rule in the input chain.
Forward – This chain is used for incoming connections that aren’t actually being delivered locally. Think of a router – data is always being sent to it but rarely actually destined for the router itself; the data is just forwarded to its target. Unless you’re doing some kind of routing, NATing, or something else on your system that requires forwarding, you won’t even use this chain.
Output – This chain is used for outgoing connections. For example, if you try to ping howtogeek.com,
iptableswill check its output chain to see what the rules are regarding ping and howtogeek.com before making a decision to allow or deny the connection attempt.
Even though pinging an external host seems like something that would only need to traverse the output chain, keep in mind that to return the data, the input chain will be used as well. When using
iptablesto lock down your system, remember that a lot of protocols will require two-way communication, so both the input and output chains will need to be configured properly. SSH is a common protocol that people forget to allow on both chains.
Policy chain default behavior
More times than not, you’ll want your system to accept connections by default. Unless you’ve changed the policy chain rules previously, this setting should already be configured. Either way, here’s the command to accept connections by default:
iptables --policy INPUT ACCEPT iptables --policy OUTPUT ACCEPT iptables --policy FORWARD ACCEPT
If you would rather deny all connections and manually specify which ones you want to allow to connect, you should change the default policy of your chains to drop. Doing this would probably only be useful for servers that contain sensitive information and only ever have the same IP addresses connect to them.
iptables --policy INPUT DROP iptables --policy OUTPUT DROP iptables --policy FORWARD DROP
Connection-specific responses
Accept – Allow the connection.
Drop – Drop the connection, act like it never happened. This is best if you don’t want the source to realize your system exists.
Reject – Don’t allow the connection, but send back an error. This is best if you don’t want a particular source to connect to your system, but you want them to know that your firewall blocked them.
Answer
iptables -A INPUT -s 10.0.0.0/8 -j ACCEPT
iptables -A OUTPUT -d 10.0.0.0/8 -j ACCEPT
Explanation
man iptables:
-A,--append chain rule-specification— Append one or more rules to the end of the selected chain. When the source and/or destination names resolve to more than one address, a rule will be added for each possible address combination.
Answer
iptables -P INPUT DROP
iptables -P OUTPUT DROP