Linux: Difference between revisions
Line 338: | Line 338: | ||
== SSH Tunneling == | == SSH Tunneling == | ||
Say I'm trying to access 10.101.1.10 server via SSH which is behind a restrictive firewall through 64.106.170.61. | Say I'm trying to access 10.101.1.10 server via SSH which is behind a restrictive firewall through 64.106.170.61. The first command will map the port 50010 of the local machine to port 22 of 10.101.1.10 that is accessible from 64.106.170.61. | ||
{| class="wikitable" border="1" style="border-collapse:collapse" | {| class="wikitable" border="1" style="border-collapse:collapse" | ||
! style="text-align: center;"| Description | ! style="text-align: center;"| Description | ||
! Command | ! Command | ||
! | ! Distro | ||
|- | |- | ||
| Create a SSH tunnel & connect via port 50010 | | Create a SSH tunnel & connect via port 50010 | ||
| class="cli" | $ ssh -L 50010:10.101.1.10:22 mhan@64.106.170.61<br>$ ssh -p 50010 127.0.0.1 | | class="cli" | $ ssh -L 50010:10.101.1.10:22 mhan@64.106.170.61<br>$ ssh -p 50010 127.0.0.1 | ||
| | | | ||
|} | |} | ||
Revision as of 09:55, 24 April 2020
System
Description | Command |
---|---|
Boot into CLI mode | sudo systemctl set-default multi-user.target |
Boot into desktop mode | sudo systemctl set-default graphical.target |
Detach a job from the current session | sudo rsync templates/* whatever/ & jobs disown -h %1 |
SSH
Description | Command |
---|---|
Create private/public SSH key file using 2048 bit encryption and with a comment. The command creates files under ~/.ssh folder. | ssh-keygen -b 2048 -C user@host.domain |
Push public SSH key to a server | ssh-copy-id -p 41111 -i ~/.ssh/id_rsa.pub mhan@remote.server.com |
Reset (SELinux) permissions related to SSH. This may be needed if all else fails to correct the issue of system not accepting public keys. | restorecon -R -v ~/.ssh |
Disk
Description | Command |
---|---|
Check if GRUB is installed on a partition (e.g. /dev/sda) | sudo dd bs=512 count=1 if=/dev/sda 2>/dev/null | strings |
Search
- xargs - to be processed - Things you (probably) didn’t know about xargs
LVM
Physical volume
Description | Command |
---|---|
Initialize for use as LVM physical volume. | pvcreate /dev/sdb1 |
Scanning for block devices. | lvmdiskscan |
Display the physical volumes. | pvdisplay |
Show all physical devices. | pvscan |
Prevent allocation of physical extents on the free space of one or more physical volumes. | pvchange -x n /dev/sdb1 |
Resize. | pvresize |
Remove LVM label. | pvremove |
Volume group
Description | Command |
---|---|
Create a volume group. | vgcreate vg1 /dev/sdb1 /dev/sdc1 |
Add a physical volume to a volume group. | vgextend vg1 /dev/sdd1 |
Display volume group. | vgdisplay new_vg |
Scan disks for volume groups. | vgscan |
Remove a physical volume from a volume group. | vgreduce group_name /dev/sdc1 |
Change the maximum number of logical volumes of volume group vg00 to 128. | vgchange -l 128 /dev/vg00 |
Activate or deactivate a volume group. | vgchange -a n my_volume_group |
Remove a volume group. | vgremove officevg |
Split the physical volumes of a volume group and create a new volume group. | $ vgsplit bigvg smallvg /dev/ram15 Volume group "smallvg" successfully split from "bigvg" |
Merge the inactive volume group my_vg into the active or inactive volume group databases giving verbose runtime information. | vgmerge -v databases my_vg |
Change the name of a volume group. | vgrename vg02 my_volume_group |
Users
UID or GID
Description | Command |
---|---|
Check UID. | id -u username |
Check GID. | id -g username |
Check all of the groups a user belongs to. | id -G username |
Check UID and all of the groups a user belongs to. | id username |
File
Permissions
Letter | Number |
---|---|
r | 4 |
w | 2 |
x | 1 |
rw- | 6 |
r-x | 5 |
rwx | 7 |
Audio
ALSA (Advanced Linux Sound Architecture)
Setting default output device
Ref: StackExchange/superuser: How to make Alsa pick a preferred sound device automatically?
List all audio cards you have:
$ cat /proc/asound/cards
0 [PCH ]: HDA-Intel - HDA Intel PCH
HDA Intel PCH at 0xf7530000 irq 41
1 [NVidia ]: HDA-Intel - HDA NVidia
HDA NVidia at 0xf7080000 irq 17
2 [SoundBar ]: USB-Audio - Dell AC511 USB SoundBar
Dell Dell AC511 USB SoundBar at usb-0000:00:14.0-4, full speed
Get ALSA identifiers of those:
$ aplay -l | awk -F \: '/,/{print $2}' | awk '{print $1}' | uniq
PCH
NVidia
SoundBar
Update /etc/asound.conf:
pcm.!default {
type hw
card SoundBar
}
ctl.!default {
type hw
card SoundBar
}
I found that the numeric identifier for these cards and change on reboot. That may be related to how the hardware detection works on Linux, and the order changes time to time. So I've used the string identifier instead -- seems to stick better than a numeric value.
PulseAudio
Restart pulseaudio. Do not sudo for this.
$ pulseaudio -k && pulseaudio -D
List sinks.
$ pacmd list-sinks
1 sink(s) available.
* index: 0
name: <alsa_output.usb-Dell_Dell_AC511_USB_SoundBar-00-SoundBar.analog-stereo>
driver: <module-alsa-card.c>
flags: HARDWARE HW_MUTE_CTRL HW_VOLUME_CTRL DECIBEL_VOLUME LATENCY DYNAMIC_LATENCY
state: SUSPENDED
suspend cause: IDLE
priority: 9049
volume: front-left: 26202 / 40% / -23.89 dB, front-right: 26202 / 40% / -23.89 dB
balance 0.00
base volume: 107931 / 165% / 13.00 dB
volume steps: 65537
muted: no
current latency: 0.00 ms
max request: 0 KiB
max rewind: 0 KiB
monitor source: 0
sample spec: s16le 2ch 44100Hz
channel map: front-left,front-right
Stereo
used by: 0
linked by: 0
configured latency: 0.00 ms; range is 0.50 .. 2000.00 ms
card: 1 <alsa_card.usb-Dell_Dell_AC511_USB_SoundBar-00-SoundBar>
module: 7
properties:
alsa.resolution_bits = "16"
device.api = "alsa"
device.class = "sound"
alsa.class = "generic"
alsa.subclass = "generic-mix"
alsa.name = "USB Audio"
alsa.id = "USB Audio"
alsa.subdevice = "0"
alsa.subdevice_name = "subdevice #0"
alsa.device = "0"
alsa.card = "0"
alsa.card_name = "Dell AC511 USB SoundBar"
alsa.long_card_name = "Dell Dell AC511 USB SoundBar at usb-0000:00:14.0-4, full speed"
alsa.driver_name = "snd_usb_audio"
device.bus_path = "pci-0000:00:14.0-usb-0:4:1.0"
sysfs.path = "/devices/pci0000:00/0000:00:14.0/usb3/3-4/3-4:1.0/sound/card0"
udev.id = "usb-Dell_Dell_AC511_USB_SoundBar-00-SoundBar"
device.bus = "usb"
device.vendor.id = "413c"
device.vendor.name = "Dell Computer Corp."
device.product.id = "a503"
device.product.name = "Dell AC511 USB SoundBar"
device.serial = "Dell_Dell_AC511_USB_SoundBar"
device.string = "front:0"
device.buffering.buffer_size = "352800"
device.buffering.fragment_size = "176400"
device.access_mode = "mmap+timer"
device.profile.name = "analog-stereo"
device.profile.description = "Analog Stereo"
device.description = "Dell AC511 USB SoundBar Analog Stereo"
alsa.mixer_name = "USB Mixer"
alsa.components = "USB413c:a503"
module-udev-detect.discovered = "1"
device.icon_name = "audio-card-usb"
ports:
analog-output: Analog Output (priority 9900, latency offset 0 usec, available: unknown)
properties:
active port: <analog-output>
Networking
How To Use Nmap to Scan for Open Ports on your VPS
Description | Command | Distro |
---|---|---|
Scan a network for connected computers | $ sudo nmap -sP 129.24.22.0/24 |
Firewall
Description | Command | Distro |
---|---|---|
Open a firewall port | $ sudo ufw allow 55301 | |
Open a firewall port | $ sudo firewall-cmd --zone=public --add-port=55301/tcp --permanent $ sudo firewall-cmd --reload |
|
Close a firewall port | $ sudo ufw deny 55301 | |
Close a firewall port | $ sudo firewall-cmd --zone=public --remove-port=55301/tcp --permanent $ sudo firewall-cmd --reload |
|
SSH Tunneling
Say I'm trying to access 10.101.1.10 server via SSH which is behind a restrictive firewall through 64.106.170.61. The first command will map the port 50010 of the local machine to port 22 of 10.101.1.10 that is accessible from 64.106.170.61.
Description | Command | Distro |
---|---|---|
Create a SSH tunnel & connect via port 50010 | $ ssh -L 50010:10.101.1.10:22 mhan@64.106.170.61 $ ssh -p 50010 127.0.0.1 |
Security
Links
Miscellaneous
- X11 - X Window System
- i3wm - i3 window manager
- Running Steam on CentOS 7 with NVIDIA driver