# Linux - Command Line Struggles

URL: https://krash.dev/linux-cli-reference/
Published: 2022-07-04
Tags: infrastructure-security, linux, sysadmin, cli, command-line, ssh

> This blog is a reference for the linux commands that I forget. The commands are mentioned according to different scenarios.


## Configure Network Using `ip` Command in Ubuntu Server
**Temporary Method -** 
```bash
$ ip a # to get the interface name after connecting LAN
$ sudo ip a add 192.168.1.8/24 dev <network-interface-name>
$ ip link set dev <network-interface-name> up
$ sudo ip route add default via 192.168.1.1
```

**Permanent Solution -**
Ref: https://netplan.io/examples/
```bash
$ vim /etc/netplan/00-installer-config.yaml

network:
  version: 2
  ethernets:
    enx1027f579a565:
      dhcp4: false
      addresses: [192.168.1.10/24]
      nameservers:
        addresses: [8.8.8.8,8.8.4.4,192.168.1.1]
      routes:
        - to: default
          via: 192.168.1.1

$ sudo netplan apply # or  sudo netplan --debug apply
```


## Allow `ssh` Connection After Lid Down
```bash
$ sudo vim /etc/systemd/logind.conf
# Make the necessary changes
...
[Login]
#NAutoVTs=6
#ReserveVT=6
#KillUserProcesses=no
#KillOnlyUsers=
#KillExcludeUsers=root
#InhibitDelayMaxSec=5
#UserStopDelaySec=10
#HandlePowerKey=poweroff
#HandleSuspendKey=suspend
#HandleHibernateKey=hibernate
HandleLidSwitch=ignore
#HandleLidSwitchExternalPower=suspend
HandleLidSwitchDocked=ignore
#HandleRebootKey=reboot
#PowerKeyIgnoreInhibited=no
#SuspendKeyIgnoreInhibited=no
#HibernateKeyIgnoreInhibited=no
LidSwitchIgnoreInhibited=no
#RebootKeyIgnoreInhibited=no
#HoldoffTimeoutSec=30s
#IdleAction=ignore
...
```

## Show Battery State
```bash
alias battery="upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -E 'state|time\ to\full|percentage'"
```

## Connect to Wi-Fi
```bash
$ sudo vim /etc/netplan/00-installer-config.yaml

network:
  version: 2
  ethernets:
    ...
  wifis:
    wlo1:
      dhcp4: false
      addresses: [192.168.1.10/24]
      nameservers:
        addresses: [8.8.8.8,8.8.4.4,192.168.1.1]
      access-points:
        "Access Point Name":
          password: "Password"
```
Then apply the configuration - 
```bash
$ sudo netplan apply --debug
```

## chmod 400 on Windows
My use case - **Setting permissions on a SSH Key File** 

Use the following command in PowerShell - 
```powershell
$path = ".\key-file-path.pem"

# Reset to remove explicit permissions
icacls.exe $path /reset

# Give current user explicit read-permission
icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"

# Disable inheritance and remove inherited permissions
icacls.exe $path /inheritance:r
```

> **Original Source** - https://stackoverflow.com/questions/43312953/using-icacls-to-set-file-permission-to-read-only/43317244#43317244

