SSH Command in Linux with examples

Permissions and ownership commands in Linux

Control who can read, change and run a file, and become the administrator when you need to.

#chmod

Change permissions

Syntaxchmod mode file
  • chmod 644 index.html

    Owner reads and writes; everyone else reads

  • chmod 755 deploy.sh

    Everyone can run it; only the owner can change it

  • chmod 600 ~/.ssh/id_ed25519

    Private keys must be readable only by you

  • chmod +x script.sh

    Make a file runnable

  • chmod -R g+w /srv/shared

    Give the group write access to a whole folder

TipThe three digits are owner, group and others. 4 = read, 2 = write, 1 = run, and you add them up: 6 = read + write, 7 = all.

#chown

Change the owner

Syntaxchown owner[:group] file
  • sudo chown deploy file.txt

    Make deploy the owner

  • sudo chown deploy:www-data file.txt

    Change owner and group together

  • sudo chown -R www-data:www-data /var/www/site

    Apply to a whole folder

#chgrp

Change the group

Syntaxchgrp group file
  • sudo chgrp developers project/

    Give the folder to the developers group

#umask

Default permissions for new files

Syntaxumask [mask]
  • umask

    Show the current mask (often 0022)

  • umask 077

    New files are private to you in this shell

#sudo

Run one command as the administrator

Syntaxsudo command
  • sudo apt update

    Run a command as root

  • sudo -i

    Open a root shell (type exit to leave)

  • sudo -u postgres psql

    Run a command as another user

  • sudo !!

    Repeat the previous command with sudo

Carefulsudo cd does not work. cd is built into the shell, so sudo cannot start it. Use sudo -i for a root shell, or sudo ls /folder to look inside.

#su

Switch user

Syntaxsu [-] [user]
  • su - deploy

    Become deploy, with that user's environment

  • sudo su -

    Become root using your own password

#whoami

Show who you are logged in as

Syntaxwhoami
  • whoami

    Prints your user name

#id

Show your user and group numbers

Syntaxid [user]
  • id

    uid, gid and every group you belong to

  • id deploy

    The same for another user

#groups

List groups

Syntaxgroups [user]
  • groups

    Groups you are in

#getfacl / setfacl

Fine-grained permissions (ACL)

Syntaxsetfacl -m u:user:rwx path
  • setfacl -m u:alice:rw report.txt

    Let alice read and write one file

  • getfacl report.txt

    Show the access list

Run these commands with SSH Command

SSH Command is a desktop app for Mac, Windows and Linux that puts a real terminal, SFTP file panes, a sudo switch and a searchable Linux command finder in one window. Type what you want to do, and send the command to your server with one click.

Download free Windows commands with examples SFTP & FTP client