server_readme.md 2.4 KB

##SERVER COMMANDS (most need sudo):

LINUX:

  • lsof -i:PORT --> list processes listening on PORT on linux
  • ss -ltnp --> list processes listening on various ports
  • ip a --> various machine ips
  • top, nohup --> old friends
  • journalctl -xe --> ???

SSH:

  • ssh-keygen --> generate public/private key pair. TAKE CARE OF THE FORMAT: EGI virtual machines seem to NEED RSA. The public key needs to be saved in /home/USERNAME/.ssh, and to be cat-ed in the /home/USERNAME/.ssh/authorized_keys file. The private key needs to be used by the user wanting to login; on linux, permissions must be 700.
  • ssh-add PRIVATE_KEY --> add the PRIVATE_KEY to the ssh service, so it won't need to be passed each time. Works with scp too
  • ssh -i PRIVATE_KEY user@server --> connect to server using PRIVATE_KEY. -i PRIVATE_KEY works for scp too.
  • ssh-copy-id user@server --> can be used to copy the/a public key to the server; probably needs password authentication enabled, check. --> it's useful to also check the sshd (ssh daemon) configuration, for instance to enable/disable password login

APACHE: Note -- most apache commands are shortcuts to stuff that can be done in other, more direct and "handmade" ways

  • systemctl start/stop/restart/reload apache2
  • a2ensite NOMESITO --> apache2 command to add 'site' (configuration file NOMESITO.conf in /etc/apache2/sites-available) to sites-enabled
  • a2enmod proxy --> command to enable reverse proxy setup in virtualhost (use together with proxy_http)
  • a2enmod proxy_http --> command to enable reverse proxy setup in virtualhost (use together with proxy)

PYTHON:

  • waitress-serve --listen=127.0.0.42:5000 app:app --> example of command to serve flask app (file app.py, app name = app) on the waitress WSGI

DOCKER:

  • docker exec -it CONTAINER bash --> explore filesystem Docker of specified container (with bash); more generally, 'docker exec' will execute commands on it. The container has to be running.
  • docker run -d --name CONTAINER -p 80:80 IMAGE --> example of running Docker: run specified image in container named 'CONTAINER'; expose internal port 80 on external port 80 (-p); detach (-d)
  • docker images --> check existing Docker images
  • docker ps [-a] --> check running [all] docker containers
  • docker rm CONTAINER --> delete specified container
  • docker image rm IMAGE --> delete specified image
  • docker container logs CONTAINER --> check container logs