Linux
Basic Commands
Useful everyday commands
List directory contents:
| |
List block devices (all drives)
| |
Get info on system
| |
Get DNS configuration on linux server
| |
Can also check file for DNS settings:
| |
Change file mode bits (file permissions)
| |
Change ownership of file
| |
Compress file
| |
Display file contents or join files
| |
Add user
| |
Install packages
Install with apt
| |
list available packages:
| |
Install specific package:
| |
##Copy Copy a file:
| |
copy multiple files:
| |
Prevent overwriting: (will overwrite files by default)
| |
Copy directory:
| |
Copy contents of directory to another directory:
| |
Sort
Pipe output to sort to sort it or display contents of file sorted:
| |
| |
Sort on numerical value:
| |
sort in reverse order:
| |
Sort by specific column (useful with commands that return data in columns like du)
| |
| |
Sort and remove duplicates
| |
Ignore case when sorting
| |
sort by human numeric values:
| |
Redirect output to another file:
| |
zip
Decompress tar.gz files:
| |
Disk Usage
Disk usage commands:
| |
install ncdu to scan folders and provide a useful menu to navigate:
| |
Get Linux Info
Get current build and Linux OS data:
| |
Get init system the server uses
| |
Remote Desktop Protocol App for linux
Remmina can be used for RDP connections to windows computers using RDP as well as VNC SSH and others
To user also need to install xrdp and tightvnc:
| |
| |
Other newer option is xserver-xorg-core
Change or Set IP address
With Newer Ubuntu versions netplan is used as the network management tool.
Get ip address and interfaces with:
| |
| |
| |
Set the network interface settings on the configuration files located in the netplan directory. Netplan will parse all the files in this directory:
| |
Example of the .yaml file:
network: ethernets: ens160: dhcp4: no addresses: - 192.168.50.15/24 routes: - to: default via: 192.168.50.1 nameservers: addresses: 1.1.1.1 version: 2 Apply the changes using netplan apply:
| |
The use of gateway4: option to set the default gateway has ben depreciated so you need to set a default route with the following option now:
| |
Swap File
Check size of swap file:
| |
increase swap file to 8GB:
| |
| |
| |
| |
| |
Alternate commands to make 8GB swap file
| |
| |
| |
App Image
Apps can be downloaded as an appimage which is the application with everythign it needs to run in one file.
You will need to make the appimage executable to be able to run it:
| |
SSH
Enable SSH Install openssh server:
| |
login.
Enable login using ssh Keys
Generate keys: Be careful if you have already generated a key as this will overwrite the current key
| |
This gets stored in ~/.ssh
Copy key to server (must have ssh via password enabled)
| |
This gets sored on remote server in ~/.ssh/authorized_keys file. you can append keys to this fille to add more logins:
| |
Copy over manually:
Check public key
| |
Make dir:
| |
copy key over:
| |
Disable Password Authentication
Edit config file:
| |
Change:
| |
Restart ssh service:
| |
Services
Show services:
| |
Set service to start on boot (linux systemd init)
| |
get process by id
| |
Mount Network Share
Mount a network share using the mount command. You may need to install cifs:
| |
then mount with this command:
| |
To automatically mount a share on reboot you need to add the details to the /etc/fstab file:
| |
Manage Disks with LVM
display all of the available block storage devices that LVM can potentially manage, use the lvmdiskscan command:
| |
display all of the physical devices on your system by using lvmdiskscan with the -l option, which will only return physical volumes:
| |
The pvscan command is similar in that it searches all available devices for LVM physical volumes. The output format includes a small amount of additional information:
| |
can also use the pvs command to show useful info:
| |
get info on lvm groups:
| |
Check LVM disks
Use commands to see free space then check space in volume group
| |
resize LVM disks
identify your setup:
| |
After increasing the disk on hypervisor:
| |
If a completely new disk was added:
| |
If disk size change is not seen to be able to resize the partition then you may need to have the system scan for disk changes first:
| |
Use the lvextend command to resize disks:
| |
Use the resize command to resize the file system
| |
Create new VG and LV
Create a Physical Volume (PV)
| |
Create a Volume Group (VG)
| |
Create a Logical Volume (LV)
| |
Format the Logical Volume (LV)
| |
Mount the Volume:
| |
Add to /etc/fstab for auto-mount:
Get the UUID:
| |
Control groups
List control groups:
| |
Modify sudos file
Change what users have access to be super users with the sudoers file:
| |
allow user to perform root commands without entering in passwords, enter the following into the sudoers file:
| |
Domain Join Linux server
To domain join linux server use realmd:
Install and configure:
| |
Files used to config domain authentication:
/etc/sssd/sssd.conf**
Configures SSSD for Active Directory integration
Set domain info, id_provider, access_provider, use_fully_qualified_names, etc.
- /etc/ssh/sshd_config**
Adjust SSH server settings (e.g., AllowGroups) to allow domain user groups to login
Possibly enable or disable UsePAM, PasswordAuthentication, or other SSH options
- /etc/krb5.conf** (often managed automatically by realm or adcli)
Kerberos config for authentication realm and KDC details
Will need to be installed with “sudo apt install krb5-user”
- /etc/nsswitch.conf**
Ensure sss is included for passwd, group, and shadow entries
pam config files /etc/pam.d/
- sshd and possibly common-auth or common-account to integrate PAM with SSSD
- Typically managed automatically by realmd but worth confirming
Add users to sudoers file (domain admins)
get info on the groups to add by using the id command:
| |
Get the group name from a user that is part of the group. Then add the group to the sudoers file:
| |
For cleaner management use the sudoers.d directory which is included in the sudoers file. This will add any files in this directory to the sudoers file so you can keep the management of access in separate files:
| |
Check authentication
| |
Enable Linux VM as Router
You can use a Linux VM as a router by enabling IP forwarding. This may be useful in some cases like in azure to enable routing between vnets in a hub spoke topology:
Enable IP forwarding:
| |
to persist the setting:
| |
In azure it will require the NIC of the vm to have the “Enable IP forwarding” to be enabled.