nix alt Flashcards

1
Q

How to set a password for a user?

A

passwd [username]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to lock an account?

A

usermod -L [username]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to unlock an account?

A

usermod -U [username]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Find all PIDS owned by the user?

A

pgrep -u [username]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

list all processes from user?

A

ps -f f -u username

ps -f –pid $(pgrep -u tecmint)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What files is used to configure how new users are created?

A

cat /etc/login.defs on redhat systems and cat /etc/deluser.conf on debian systems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Killall processes from user?

A

killall -9 -u username

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Delete user and home files?

A
Delete user and home files? 
	# deluser --remove-home tecmint      [On Debian and its derivatives]
# userdel --remove tecmint           [On RedHat/CentOS based systems]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

(list all the network services and what their default listening ports are

A

cat /etc/services

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

check your gateway

A

netstat -rn

^i think that’s all you need, the verbose flag doesn’t really give you anything extra but maybe it’s good just in case?

netstat -rnv

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

one way to ssh key

A
  1. ssh-keygen (run this on client)
    1. ssh-copy-id root@192.168.1.1 (copy over your key)
    2. ssh root@192.168.1.1 (login with no pass)
      a. or ssh -l root 192.168.1.1 (same thing, different syntax)
      and you can check your stuff on the server by cat /root/.ssh/authorized_keys

(you could’ve manually placed this key in that file too instead of using the ssh-copy-id thing)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the commands you would run if you need to find out the version and build date of a package (e.g. http)?

A

rpm –qi httpd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

If you create a new group, which file does it get created in?

A

/etc/group

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

To view your command history, which command is used and how to run a specific command?

A

history and !#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to create a soft link?

A

ln –s

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to get information on all the packages installed on the system?

A

rpm –qa

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How to upgrade Linux from 7.3 to 7.4?

A

yum install update

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

what are some hardening commands and config files and such?

A

change default user create settings
cat /etc/default/useradd
cat /etc/login.defs

check running services and adjust stuff you want on/off
netstat -tunlp

turn off root login and other settings for ssh
cat /etc/ssh/sshd_config

setup a firewall
firewalld or iptables

use SELinux

cat /etc/login.defs (change default password settings)
chage -l [username] (check password stuff for user)
cat /etc/shadow
chage (you can use this to change pass settings too)
cat /etc/passwd (see users and if they have shell access and stuff)

??? cat /etc/pam.d/system-auth (something with security?)

systemctl -a (check the services, see if there’s anything you can stop/disable/mask etc)

netstat -tunlp (check what serves are listening and on what ports, then stop/disable the stuff you don’t need)

cat /etc/ssh/sshd_config (change the port that ssh listens on, disable root login, etc. You can go in here and turn off passwordauthentication if you have ssh keys setup - this is a good security thing)

firewall-config (this gives you a gui to disable services, ports, blah blah)
firewall-cmd –help (instructions on how to do the above without a gui)
cat /etc/firewalld/firewalld.conf (configure the basic firewall settings here)

[enable/disable firewalld or iptables and set rules and stuff]

iptables -L (lists iptables rules)
iptables -F (flushes the iptables rules so you have 0)

cat /etc/sysconfig/iptables-config (adjust some iptable settings like how it saves and stuff)

SELinux controls permissions of processes and applications - can’t do this with normie linux
sestatus (checks if SELinux is enabled)
cat /etc/sysconfig/selinux (controls state of SELinux on the system, disable, permit, enforce, etc)
stat [filename] (this gives you the permission details of stuff)
man chcon (change SELinux security context of stuff)
man checkpolicy (selinux policy compliler)

cat /etc/sudoers (you can check this to see who can do root stuffs)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Which 2 files contain default values when creating a user with useradd command?

A

cat /etc/default/useradd

cat /etc/login.defs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Create a user with a predefined uid, shell, and home directory

A

useradd -m -d /home/user -s /bin/bash -u 9000 user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Delete a user with his home directory

A

userdel -r user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Create a user specifying a primary/secondary group

A

useradd user -g primary -G other groups

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Change primary grup for any user

A

usermod -g primarygroup user

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Give sudo access to any user without asking him to privde password everytime he runs a command

A

user ALL=(ALL) NOPASSWD:ALL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How to check mtu, ip and MAC address?

A

ifconfig

^this seems to do the same thing. not even sure if -a is a real flag lol what
ifconfig -a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Find running processes on your system

A

ps -ef

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

How to view all messages generated by thte system since the last reboot on RHEL7

A

journalctl

journalctl | grep ssh

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What are the two different ways of showing the kernal messages?

A

journalctl -f
tail -f /var/log/messages
less +F /var/log/messages

29
Q

Where can you find messages related to the installation of linux?

A

/var/log/anaconda.log

…dunno about the rest of these
anaconda.log
/var/log/anaconda/anaconda.log

30
Q

To improve performance, how can you safely set the limit of processes for the super user root to be unlimited?

A

ulimit -u unlimited

31
Q

How to check the ulimit for a user?

A

ulimit -a

32
Q

How to check and increase the limit of opened files in linux?

A

cat /proc/sys/fs/file-max

	to change:
	1 - vi /etc/sysctl.conf
	(and add line)
	2 - fs.file-max=98321
	3 - sysctl -p
cat /proc/sys/fs/file-max
33
Q

How to view run time kernel parameters?

A

sysctl -a

34
Q

How can you get the physical and virtual memory statistics?

A

free -m or g
vmstat -a (active and inactive memory), -d disk stats -t time
vmstat -a 2 (every 2 sec) 4 (4 intervals)

35
Q

How to check cpu utilization and other statistics?

A

User sar which part of sysstat package

sar -u shows cpu utilization stats for the current day
sar -u 2 3 shows realtime cpu stats every 2 seconds with 3 intervals
sar -r meomory utilization sar -s swap space
36
Q

How to find process id of a process and kill it immediately?

A

start cat
pidof cat
kill -9 PID

37
Q

How to list all open files specified by user?

A

lsof -u user

38
Q

How to list all files opened by a particular command?

A

lsof -c cat

39
Q

How can you list all network connections by port 22?

A

lsof -i :22

40
Q

Run a command that shows all lines except any lines starting with the character # in a file

A

cat [file] | grep -v ^#

41
Q

How to remove files older than 7 days be creating a cron job to run every night?

A

find [directory] -type f -mtime +7 -exec rm -rf {} \;

crontab -l (show crontab for current user)
cat /etc/crontab (instructions on how to run the file)
crontab -e (edits the crontab - but you can also place stuff/scripts in cron directories …) 0 2 * * * ewig /bin/find [directory] -type f -mtime +7 -exec rm -rf {} \;
42
Q

How to create a user with no login access?

A

useradd -s /sbin/nologin username

43
Q

How to schedule a reboot in 15 minutes?

A

shutdown -r +15

44
Q

How do you find the disk usage by the largest directories?

A

df -h | sort -n

du -Sh / | sort -nr | head

45
Q

How to prevent users from deleting other users files in a directory?

A

special permissions, sticky bit
chmod 1777 filename
chmod 1600 filename
etc

46
Q

Show line numbers of a cat’d file?

A

cat -n filename

47
Q

How to print the 10th line of a file only?

A

head -10 filename | tail -1

48
Q

How to disable ping?

A

temp:
echo “1” > /proc/sys/net/ipv4/icmp_echo_ignore_all

permanent
step 1:
	edit the sysctl.conf file and add the following line

	net.ipv4.icmp_echo_ignore_all = 1
step 2:
	execute sysctl -p to enforce this setting immediately

sysctl -p

49
Q

How to check if a port is listening?

A

netstat -lepunt | grep :22

netstat -anp | grep :22

50
Q

Find files with specific permissions in specific directories

A

find /folder -perm 755

51
Q

How to change the default ssh port?

A

edit /etc/ssh/ssh_config and change port 22 to whatever then restart sshd

52
Q

How to disable ssh root login?

A

change /etc/ssh/sshd_config permitrootlogin to no

53
Q

How to allow only specific users to ssh into your server?

A

/etc/ssh/sshd_config and add paramter AllowUsers user1 user2 then restart ssh

54
Q

How to setup sshkey login

A

ssh-keygen on the client
ssh-keygen
ssh-copy-id your public key to the server
ssh-copy-id -i path/to/certificate username@remote_host

55
Q

Find files over 10MB in size

A

find /folder -size +10M

56
Q

Find total lines in a file without opening it

A

wc -l filename

57
Q

Find all directories named conf under root?

A

find / -type d -name conf

58
Q

Find files not accessed in over 3 days?

A

find /etc -atime +3

59
Q

Find all files in the current directory and modify their permissions.

A

find . -type f -exec chmod 644 {} \;

60
Q

Do an ls at 11:30pm

A

at 11:30pm 3/31/2020
[type ls in the prompt and press enter]
[press ctrl + d to finish]

61
Q

List spooled jobs

A

at -l
atq
ll /var/spool/at

62
Q

Remove spooled jobs

A

at -d 5

63
Q

How do you check what user groups you’re part of and everything?

A

vim /etc/login.defs

64
Q

What if disk space is full?

A

df -h | grep -v tmpfs

65
Q

What if you can’t copy/rename/delete/remove a file?

A
  • check if it exists
  • check the command your’e using, absolute vs relative paths too
  • check the file type
  • check the permissions, attributes, stat, immutability and so forth
  • check parent directory permission
66
Q

What if “server not reachable”

A

ping destination server
telnet server ip
nmap server ip

if it’s not pingable there …
- check /etc/hosts, /etc/resolv.conf, /etc/nsswitch.conf

check that you have an ip
run traceroutes
check firewall

67
Q

Unable to get ip address

A

ifconfig
lspci | egrep -i ‘eth|wifi|wireless’
nmcli -p dev
ifup or ifconfig up

/usr/sbin/ifup
check /etc/sysconfig/network-scripts/ifcfg-enp0s3 or ifcfg0-eth0

68
Q

ip assigned but not reachable

A

ifconfig … check if your’e on the correct interface
check if you got the right subnet mask or gateway
ping the gateway
netstat -rnv … check that the gateway is assigned
check with the network team if the correct vLAN is assigned on the switch side
run ethtool or mii-tool to check the NIC status
run ifup command to bring the NIC port up
restart the network with systmctl restart network
check on the status of the NIC with ifconfig or ip addr
check to see if the IP is assigned to some other device (IP conflict)
turn off firewall

69
Q

assorted domain/ip issues

A
  1. first system looks at /etc/hosts to see if there’s an entry for the domain
  2. then it looks at /etc/resolv.conf to find a nameserver to go to in order to keep looking

cat /etc/resolv.conf
cat /etc/nsswitch.conf
cat /etc/hosts (you could edit this with domains you want to resolve to specific domains - and it would work depending on the order of your nsswitchconf and you can test the results with getent hosts domain.com)

by default system looks locally for dns resolution before looking elsewhere
edit /etc/nsswitch.conf to edit that under #hosts
hosts: files dns myhostname

if there’s an entry in hosts file,

change host (update /etc/hostname)
	hostnamectl set-hostname [hostname_you_select_]

Resolv conf overwritten by Network Manager
To prevent Network Manager to overwrite your resolv. conf changes, remove the DNS1, DNS2, … lines from /etc/sysconfig/network-scripts/ifcfg-* . Now, you can manually change the /etc/resolv

One way to stop Network Manager from adding dns-servers to /etc/resolv.conf file is to do this:

First open the nm conf file /etc/NetworkManager/NetworkManager.conf:

sudo vim /etc/NetworkManager/NetworkManager.conf

And add this to the [main] section:

dns=none

I had to sudo service network-manager restart before the change to the .conf file took effect.