Remotely on Ubuntu Linux Server from Local Mac

«  Digital Root
Flutter Study Memo  »

1. Enable ssh

From both

ssh username@hostname(ip address or domain name)

# enable ssh server on Ubuntu
sudo systemctl enable ssh

# start ssh services
sudo systemctl start ssh
# stop ssh services
sudo systemctl stop ssh
# restart ssh services
sudo systemctl restart ssh

# view ssh status
sudo systemctl status ssh

# disable and remove ssh servers
sudo systemctl stop ssh
sudo systemctl disable ssh
sudo apt-get remove openssh-server

some ssh settings on MacBook:

# copy ssh ip_rsa from MacBook to Linux
ssh-copy-id -i ~/.ssh/id_rsa.pub user@host

Troubleshooting:

Linux warning no ssh command

install it by

sudo apt-get install openssh-client
sudo apt-get install openssh-server

Firewall block ssh access

  • enable ssh and open ssh port
  • open ssh tcp port 22 using ufw firewall, sudo ufw allow ssh

2. GUI through XWindow forwarding

# open GUI from remote server
# -X or -Y allow XWindows of GUI apps to be forwarded to local desktop
ssh -X username@hostname
# or
ssh -Y username@hostname

NOTE:

  • if server is in an internal network, need to first connect through VPN to ssh in

3. File transfer

  • ftp use tools like FileZilla(connect server through sftp protocol, i.e. ftp via ssh)
  • mount remote directory in the naive file manager with Mac Fusion
- install Fuse for Mac
- `sshfs username@hostname:/remote/directory/path/local/mount/point`
- remote directory can be accessed using bookFinder

4. Terminal ssh with screen

Keep session alive despite lost connection, use screen. Only supports pure terminal applications, not GUI applications

  • official documentation: https://www.gnu.org/software/screen/
  • quick guide https://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/

5. GUI session via Xpra

Xpra is screen for X11.

# install xpra command
sudo apt-get install xpra

# start session
local_client> xpra start ssh/username@hostname/100 --start=xterm
# `100` is identifier of session name, different user should use different identifiers and same user can start multiple sessions by specifying distinct identifiers, ex: 101, 5000
# `xterm` is GUI program to run on start, can start any other GUI program from xterm

# disconnect from a session
# press `ctrl+c`

# attach/return to previous session
local_client> xpra attach ssh/username@hostname/100

# check xpra sessions
remote_server> xpra list

# terminate all xpra sessions
remote_server> xpra stop

# specify dpi when start or attach a session, to avoid mismatched DPI between server and client
local_client> xpra attach ssh/username@hostname/100 --dip=96

More xpra related guide:

6. NoMachine connect

NOTE: install XQuartz program on Mac

References

Published on 21 Mar 2022 Find me on Facebook, Twitter!

«  Digital Root
Flutter Study Memo  »

Comments

    Join the discussion for this article at here . Our comments is using Github Issues. All of posted comments will display at this page instantly.