How to play chess in Linux terminal (with Multiplayer support over SSH)

While playing chess online in a browser is simple, you can also host a two-player game in your terminal, against an opponent in the same room, or via SSH, meaning your opponent can be anywhere in the world.

Here's how to do it.

Gambit brings a graphical chessboard in the Linux terminal

How to play chess in Linux terminal (with Multiplayer support over SSH) Picture 1How to play chess in Linux terminal (with Multiplayer support over SSH) Picture 1

Chess is one of the greatest games of all time, whose history dates back to the 6th century Gupta Empire in India. Although the rules have improved over time, chess is still popular due to its ease of access and the mental challenge of man-to-person competition.

If you've never played chess before, don't worry; you can easily learn to play chess on your phone. Traditionally, chess is a two-player game, played on a physical board with 64 squares and 16 pieces on each side.

Before the advent of the Internet, if you wanted to play chess with someone who was not in the same room as you, each player would have to have their own chess board and announce their move via telegram, phone or text message.

 

Today, you can use mobile apps or open a web browser and join one of the many online chess sessions on dedicated websites.

But mobile apps can be expensive, and not everyone has a computer with a pre-installed web browser or even a graphical desktop.

With Gambit, you can create a game of chess right in your terminal and play with the person sitting next to you. Plus, you can join the game over SSH, meaning you can instantly play against anyone in the world.

Install Gambit on Linux

How to play chess in Linux terminal (with Multiplayer support over SSH) Picture 2How to play chess in Linux terminal (with Multiplayer support over SSH) Picture 2

Gambit is written in Google's Go language, so before you begin, make sure you have Go installed on your Linux system.

If your distro supports Snap, the easiest way to install Go is to:

sudo snap install go --classic

Once you have Go installed, you can install Gambit with:

 

go install github.com/maaslalani/gambit@latest

This command will install the Gambit binary to ~/go/bin/gambit.

You can make the binary file accessible from any terminal by creating a symlink with the ln command:

sudo ln -s ~/go/bin/gambit /usr/bin/gambit

Then you can start Gambit with:

gambit

Alternatively, you can install Gambit by cloning its GitHub repository:

git clone https://github.com/maaslalani/gambit

Then use the cd command to navigate to the new directory:

cd gambit

Finally, start Gambit with:

go run ./

If you are a lover of Snap packages, you can install Gambit with the snap command as follows:

sudo snap install gambit

How to play chess in terminal with Gambit

How to play chess in Linux terminal (with Multiplayer support over SSH) Picture 3How to play chess in Linux terminal (with Multiplayer support over SSH) Picture 3

If you've read this far, you probably know at least the basics of how to play chess.

The game starts as soon as you open Gambit, and you'll see a board complete with representations of pieces that are either white or black with white outlines.

When it's your turn to move, click on a piece. You will see a colored dot representing the space your piece can move to. Click a position to move the piece. Alternatively, if your computer doesn't have a mouse, you can use your keyboard to select the square you want to move the piece to.

The only minor annoyance you have when playing chess this way is that the tiles on the board are all black, instead of black and white. This can make it difficult to easily visualize the path for your pieces.

If you are playing against an opponent on the same computer, you can press Ctrl + F to flip the board to get a better view of the moves.

But if you're sitting next to someone, it's probably easier and a little more satisfying to open a real board and arrange the pieces. Gambit is only really useful when you want to challenge players far away.

Secure Shell (SSH) is a protocol used to securely connect to remote devices and with this protocol you can organize a game of chess with Gambit and let other players connect to the protocol there.

 

Before you start, you need to generate an SSH key. It's not in the documentation, but Gambit will reject keys generated with the RSA algorithm. You will need to use the newer ECDSA algorithm with a minimum key size of 256 bits to host a chess game over SSH with Gambit.

On the host machine, enter:

ssh-keygen -t ecdsa -b 256

Select whether you want to use a password, and then press Enter. You can find your new key pair in the "~/.ssh/" directory.

Tip : If you're playing against an opponent on a different network, the host will need to open port 53531 on the router and forward connections to the host's IP address. This requires you to have some basic knowledge of port forwarding on the router.

To start the Gambit server, enter:

./gambit serve --key ~/.ssh/id_ecdsa

Gambit will start the server on port 53531 and players can connect to the game using:

ssh host_username@remote.host.ip.address -p 53531 -t room_name

.where room_name is the name chosen by the first player to join.

Back on the host machine, you won't find a chessboard in your current terminal. Open a second window or tab, then type:

ssh your_username@localhost -p 53531 -t room_name

Now, you can play chess with your opponent.

3.7 ★ | 3 Vote