====== SSH/Xterm and Common Commands ====== The recommended way to access Batocera's terminal is through SSH from another computer on the same local network (so that you get nice features like command history and ASCII coloration). First, make sure that SSH is enabled on your Batocera machine (it is enabled by default): check ''/userdata/system/batocera.conf'' and make sure ''system.ssh.enabled=1'' (with no leading #) is present. Then use your preferred SSH tool to connect; enter ''%%ssh root@batocera%%'' or equivalent in your terminal (or the Command Prompt on Windows 10+). Windows users are advised to use [[https://www.putty.org|PuTTY]] or [[https://sw.kovidgoyal.net/kitty/|KiTTY]] to connect via SSH. The username is ''root''. This is the only user on a Batocera machine. So, the typical address to attempt an SSH connection to the Batocera machine would be ''%%root@batocera.local%%'' or just ''%%root@batocera%%''. If none of those work, you can connect to ''root@192.168.###.###'', where ''192.168.###.###'' would be the IP address that you get from **MAIN MENU** -> **NETWORK SETTINGS** in the Batocera interface. For example, this is how PuTTY should look when SSH'ing in: {{:putty_config.png?500|}} Click "Save" after everything is set up to create a double-clickable profile for convenience. Once in the SSH session, enter the password. The default password is ''linux''. While typing the password, no asterisks will appear. That is how Linux does things. If you do not want guest access, turn on "Enforce Security" from **MAIN MENU** > **SYSTEM SETTINGS** > **SECURITY** and specify a password. Turning on **ENFORCE SECURITY** will also require your username and password to access the network share as well. Despite this, keep in mind that [[:security|Batocera is not a secure operating system]] and exposing it to a public network is at your own risk. A successful login via SSH looks similar to this: {{ssh-session.png?nolink|This is referred to as ASCII art.}} A local terminal can also be accessed on the Batocera machine itself by opening ''xterm'' from the Applications menu in the file manager (''[F1]'' on the system list), however this can only be done on platforms which support the Xorg backend (such as x86_64). It is also possible to open a new TTY session from anywhere in Batocera by pressing ''[Ctrl]''+''[Alt]''+''[F5]'' (you will be asked to login, refer to above). To return to Batocera after doing this, press ''[Ctrl]''+''[Alt]''+''[F2]''. In Batocera **v31** and lower, this shortcut is ''[Ctrl]''+''[Alt]''+''[F3]''. In Batocera **v31** and lower, it is not recommended to use this terminal due to garbled text input; only use it in emergency situations. Whenever using the command line, try to understand what the commands are doing exactly. Even if it doesn't seem like it, certain commands can be used in harmful ways. For example, putting simply ''> empty.txt'' without any command will create an empty file called empty.txt in the current working directory. That's fine, right? If you already had a useful file with this name, it'll be empty after this command. Even more dangerously, a short command like ''%%rm -rf /%%'' or ''%%:(){:|:&};:%%'' could destroy your entire hard drive without prompt! Copy and paste work differently in PuTTY than in many other Windows programs. For a general introduction to PuTTY features including copy and paste, refer to the [[https://the.earth.li/~sgtatham/putty/0.52/htmldoc/Chapter3.html#3.1.1|PuTTY documentation]]. ==== Password-less authentication ==== === From a remote machine to Batocera === Batocera can remember the SSH client's key such that it no longer requires a password to type in. This section assumes that your Batocera user data partition is formatted Linux-native (ext4 by default, or btrfs). The //chmod// commands below won’t be applied correctly on FAT32 or NTFS partitions, and as a result passwordless SSH will fail. - On Batocera, run the following in terminal: chown root:root / /userdata/ /userdata/system/ chmod 755 / /userdata/ /userdata/system/ mkdir -p ~/.ssh touch ~/.ssh/authorized_keys chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys - On the client computer (the one which logs into Batocera via SSH), generate its SSH keypairs (if not already done so) and add the public Batocera SSH key to the Batocera SSH configuration as follows: * For most **Linux**-based distributions, run the following: ssh-keygen and mash ''[Enter]'' through all of the questions. Don't worry about setting a master password for the public keys. Then run: cat ~/.ssh/id_rsa.pub | ssh root@batocera.local 'cat >> /userdata/system/.ssh/authorized_keys' replacing ''batocera.local'' with the IP address of Batocera if using a static IP. * For **Windows**, paste the ''id_rsa.pub'' key from ''C:\\.ssh\id_rsa.pub'' into Batocera at ''~/.ssh/authorized_keys''. That's it. You should be able now to SSH into your Batocera system from your SSH client without entering any password. Advanced users may be tempted to use ''ssh-copy-id'' to set up the ''authorized_keys'' file. This will not work, due to limitations in the [[https://en.wikipedia.org/wiki/Dropbear_(software)|Dropbear]] setup as implemented in Batocera. === From Batocera to a remote machine === It is also possible to set up passwordless authentication the other way around: From Batocera to am remote machine. Since Batocera does use the //Dropbear// SSH service, the ''ssh-keygen'' command will not work to create a local SSH keypair. Instead, the following command will generate the according SSH keypairs: \\ ''dropbearkey -t rsa -f ~/.ssh/id_dropbear'' \\ Once done, the public SSH key will be shown on the command line window. In case you want to show the public SSH key later, do so by executing: \\ ''dropbearkey -y -f /userdata/system/.ssh/id_dropbear | grep '^ssh-rsa' > /userdata/system/.ssh/id_dropbear.pub'' You can now copy the according public SSH key to your remote machine as already shown above, but the other way around of course. ===== Basic SSH commands ===== Once you are connected to Batocera, you can use most standard Unix commands. When we say most, we mean mostly [[https://www.gnu.org/software/coreutils/manual/|the GNU coreutils]]. Batocera is a lean build-root Linux based system, which does not have a lot of the commands or packages that other distributions typically do. A lot of commands aimed at Ubuntu or Mint for example won't work here. Some command-line tools have an ''%%--help%%'' option describing how to use the program, for example, typing ''%%cp --help%%'' will print how the command is used in the command-line interface. BusyBox v1.31.1 (2020-11-28 14:11:54 CET) multi-call binary. Usage: cp [OPTIONS] SOURCE... DEST Copy SOURCE(s) to DEST -a Same as -dpR -R,-r Recurse -d,-P Preserve symlinks (default if -R) -L Follow all symlinks -H Follow symlinks on command line -p Preserve file attributes if possible -f Overwrite -i Prompt before overwrite -l,-s Create (sym)links -T Treat DEST as a normal file -u Copy only newer files Most command-line tools have a syntax similar to ''%% -