Ubuntu 16.04中signify使用方法及远程桌面连接脚本变量问题
Hey there! Let's tackle your two Ubuntu-related questions one by one:
Ubuntu 16.04 doesn't include signify in its default repositories, so we'll need to install it first. Here are two reliable methods:
Method 1: Install via PPA (if available)
Some third-party PPAs host signify for older Ubuntu versions. Try this:
sudo add-apt-repository ppa:martin-frost/thoughtbot-rcm sudo apt-get update sudo apt-get install signify
If the PPA doesn't work for 16.04, go with the source compilation method below.
Method 2: Compile from source
This is a surefire way to get signify working:
# Install build dependencies sudo apt-get install build-essential git # Clone the signify repo git clone https://github.com/aperezdc/signify.git cd signify # Compile and install make sudo make install
Basic signify Usage
Once installed, here's how to use it for common tasks:
- Generate a key pair:
You'll be prompted to set a passphrase to protect your private key.signify -G -p public.key -s secret.key - Sign a file:
This createssignify -S -s secret.key -m your-file.txtyour-file.txt.sig, the signature file for your document. - Verify a file's signature:
If the signature is valid, you'll see "Signature Verified"; if not, you'll get an error message.signify -V -p public.key -m your-file.txt
To create a script that handles both trusted (encrypted) and untrusted remote desktop connections, we'll use VNC with SSH tunneling for trusted connections, and direct VNC for untrusted. We'll also integrate your user input logic into the script.
Prerequisite: Set Up VNC Server on the Target System
First, install and configure a VNC server on the Ubuntu machine you want to connect to:
sudo apt-get install tightvncserver # Run this once to set a VNC password tightvncserver :1
This starts the VNC server on display :1 (port 5901).
Update Your myscript.sh Script
Replace your existing script with this version, which handles input and both connection types:
#!/bin/bash # Get user input read -p "Enter target Ubuntu system IP address: " target_ip read -p "Enter target system username: " target_user read -s -p "Enter target system password: " target_pass echo "" # Add a newline after password input # Untrusted Connection (Direct VNC, no encryption) echo "Establishing untrusted remote desktop connection..." # Use expect to auto-enter VNC password expect << EOF spawn vncviewer $target_ip:1 expect "Password:" send "$target_pass\r" interact EOF # Trusted Connection (Encrypted via SSH Tunnel) echo -e "\nEstablishing trusted remote desktop connection..." # Create SSH tunnel first, then launch VNC viewer expect << EOF spawn ssh -L 5901:localhost:5901 $target_user@$target_ip expect "password:" send "$target_pass\r" # Wait a moment for tunnel to establish, then launch VNC sleep 2 spawn vncviewer localhost:1 expect "Password:" send "$target_pass\r" interact EOF
Script Setup & Notes
- Install expect: The script uses
expectto handle interactive password prompts, so install it first:sudo apt-get install expect - Make the script executable:
chmod +x myscript.sh - Run the script:
./myscript.sh
Alternative: Using RDP with xfreerdp
If you prefer using RDP instead of VNC, you can modify the script to use xfreerdp:
# Untrusted RDP connection xfreerdp /u:$target_user /p:$target_pass /v:$target_ip # Trusted RDP connection via SSH tunnel ssh -L 3389:localhost:3389 $target_user@$target_ip xfreerdp /u:$target_user /p:$target_pass /v:localhost
内容的提问来源于stack exchange,提问作者Viral Nakrani

