Linux Commands and PowerShell on Linux

Date Published: February 1, 2022

This guide provides useful Linux commands for user management, account configuration, and installing PowerShell on Linux. It’s designed to help administrators perform common tasks efficiently.


General Linux Commands

Install Sudo on Debian

Debian does not include sudo by default. To install it:

apt install sudo

Add a User Account

Create a new user account and its home directory:

sudo useradd -m nameofaccounttoadd

View Sudoers List

Check the sudoers configuration file:

cat /etc/sudoers

View SSH Users

Check the allowed SSH users in the configuration file:

cat /etc/ssh/sshd_config

Change User Password

Update the password for an existing account:

sudo passwd nameofaccounttoadd

Add a User to the Sudo Group

Grant sudo privileges to a user:

sudo usermod -a -G sudo nameofaccounttoadd

To verify users in the sudo group:

getent group sudo

Set Account Expiry

Set an expiry date for a user account (effective at 00:00 hours on the specified date):

sudo usermod -e 2018-10-24 accountname

To check for expired accounts:

sudo passwd -S | grep "Password expired"

PowerShell on Linux

PowerShell provides cross-platform administrative capabilities, including on Linux. Here’s how to install and configure it:

Steps to Install PowerShell on Ubuntu

  1. Update the Package List:
    sudo apt-get update
    
  2. Install Pre-requisite Packages:
    sudo apt-get install -y wget apt-transport-https software-properties-common
    
  3. Download Microsoft Repository GPG Keys:
    wget -q https://packages.microsoft.com/config/ubuntu/16.04/packages-microsoft-prod.deb
    
  4. Register Microsoft Repository GPG Keys:
    sudo dpkg -i packages-microsoft-prod.deb
    
  5. Update the Package List Again:
    sudo apt-get update
    
  6. Install PowerShell:
    sudo apt-get install -y powershell
    
  7. Start PowerShell:
    pwsh
    

Enable Connecting to PSSession on a Linux Box

Generate SSH Key

Create an SSH key pair for secure communication:

ssh-keygen

Add Public Key to Target Machine

Add your SSH public key to the target machine’s authorized keys file:

cat ~/.ssh/id_rsa.pub

Use PowerShell for Remoting

Enable PowerShell remoting for Linux with:

Enable-SSHRemoting -UserName <username> -KeyPath ~/.ssh/id_rsa.pub