chaosink
chaosink

Reputation: 1483

notify-send doesn't work over SSH

I want to use PC A to send a notification to PC B via SSH, but I didn't see the notification on B.

ssh user_name@B_ip 'notify-send hello'

I also tried this: Use SSH on B to login A and then login B back and then send a notification. However it still didn't work. Didn't see the notification on B either.

Upvotes: 0

Views: 2819

Answers (3)

eri
eri

Reputation: 3524

For showing notifications on remote machine in modern distributions (Debian 9 and newer) for current user.

export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus
notify-send "Test Test" "testing..."

DISPLAY may be different or not set with Wayland.

Upvotes: 0

lugu
lugu

Reputation: 11

Notifications are sent via dbus (user session). You need to to tunnel the dbus socket over SSH so that a program running on another computer can send notification to your desktop.

The workflow is:

  1. Expose dbus socket to a local TCP port (only available from localhost)
  2. Reverse tunnel this local TCP port on the remote machine (using SSH)
  3. On the remote machine, expose this TCP port as an abstract socket
  4. Tell notify-send which dbus session to connect (the created abstract socket)

@local represents your desktop and @remote represents the machine you ssh to.

  1. Forward local port :7272 to dbus abstract socket (guid will be used later)
@local $ echo $DBUS_SESSION_BUS_ADDRESS
unix:abstract=/tmp/dbus-pH1JnDeLNA,guid=5fe0907d81e722390f1ce02d6033ad76
@local $ socat TCP-LISTEN:7272,reuseaddr,fork ABSTRACT-CONNECT:/tmp/dbus-pH1JnDeLNA
  1. Revert forward port 7272 from remote host (replace $REMOTE_HOSTNAME)
@local $ ssh -R localhost:7272:localhost:7272 $REMOTE_HOSTNAME
  1. Forward abstract socket to localhost:7272
@remote $ socat ABSTRACT-LISTEN:/tmp/custom_dbus_name,fork TCP:localhost:7272
  1. Launch notify-send
@remote $ export DBUS_SESSION_BUS_ADDRESS='unix:abstract=/tmp/custom_dbus_name,guid=5fe0907d81e722390f1ce02d6033ad76'
@remote $ notify-send "Hello, World"

Upvotes: 1

pacholik
pacholik

Reputation: 8992

You have to set DISPLAY variable

DISPLAY=:0.0 notify-send hello

For some information about this variable see this.

Upvotes: 2

Related Questions