Skip to content

Step 7: Linux administration

monotiller edited this page May 27, 2022 · 2 revisions

Link to discussion

Intermediate Linux administration

Introduction to SSH

Terminology

  1. Client/server: Client sends a request, a server recieves and processes it
  2. Network protocol: Any established set of rules that determines how data is transmitted between different devices is considered a network protocol a. TCP IP b. HTTP c. FTP
  3. Algorithm: Set of rules or process which needs to be followed to solve a problem
  4. Packet: Data is fragmented into packet for easier transmission
  5. Payload: Actual data within the packet
  6. Remote Server: Any computer that is not physically attached to your keyboard/monitor/mouse is considered a remote server

What is SSH?

  • Stands for: Secure Shell
  • Cryptographic network protocol to send encrypted packets over a network
  • Meant to address issues with similar tools with regards to encoding data over a network
  • The server is connected to your local keyboard/mouse/keyboard
  • Safer than putting in username/password

How it works

  • SSH uses asymmetric cipher for encryption and decryption of packets
  • This means that there needs to be a pair of keys a public and private one
  • The more complex the algorithm, the harder to decrypt the data

How SSH uses asymmetric cipher to

  1. Establish connectivity between client and server

  2. Send encrypted data across the channel

  3. A key pair has to exist

    • The public and private key
    • You cannot use a publc key that belongs to another private key
    • The client shares the public key with the remote server
    • The server has to confirm that the client is who they say they are and not someone sitting in the middle
    • Once it recieves a connection request from the client it uses the public key that it has to encrypt some random data and send it to the client to decrypt
    • If the client can't decrypt it is disconnected

Disadvantages of SSH

  1. Misconfiguration can prevent you from ever being able to log in to the system
  2. Lost private key means you are stuffed

Open SSH Server – part 2

Useful things to know

  • Connection logs are stored in /var/log/auth.log. You can use tail -f to follow updates to the folder

SUDOERS – SSHD configuration files

  • sudo is used to give you super user privaleges
  • su let's you switch to another user. For example usera can switch to userb by doing su userb assuming they have the correct permissions
  • /etc/sudoers is a file that determines who has sudo access. You can also specify new groups with permissions in this file too just in case you want to fine tune what a user can and can't do
  • groupadd allows you to create a group
    sudo groupadd devops
  • usermod alloes you to add a user to a group:
    sudo usermod -a -G devops monotiller
  • id let's you see what groups a user belongs to
  • /etc/ssh/sshd_config is a file that allows you to set some of the ssh configurations
    • PermitRootLogin allows you to specify how the root user can log in:
    PermitRootLogin no
    PermitRootLogin without-password #Means you need the private key
    
  • sudo sshd -t allows you to test the configuration for errors
  • Changes don't take place until you restart the ssh service
    sudo systemctl restart sshd

How to securely upload and download files remotely SFTP – SCP

SFTP

  • Uses SSH so you will need your key!
  • To move a folder:
    sftp [ip]
  • You are now presented with a new command line instance.
  • This is the key difference between SFTP and SCP as SCP you have to specify the destination in the command whereas SFTP allows you to interact with the host
  • put allows you to upload a file or directory from your client to the host
    • Caveat being that the directory must exist on the host too if you're uploading a directory
  • get allows you to download from the host to the client

SCP

  • scp is a lot faster to upload a file or directory
    scp -r [local directory] [user]@[ip]:[destination directory]

Process management

  • bg let's you run a process in the background which allows you to continue using that terminal instance. Very useful for processes that will take a long time such as a backup or a file transfer
    • You will need to kill the process though if you want it to stop
    • nohup allows you to bring the process forward if it's running in a separate terminal
  • fg brings a process from the background to the foreground, will take over terminal
  • jobs shows the currently running jobs
  • process shows what processes are present on the system
  • states shows processes' current state (running, sleeping, uninteruptable, etc.)
  • kill kills a process, adding the flag l let's you see what kind of kills you have available
Clone this wiki locally