turning off serial output logs in GCP vm - linux

Simple question but I can't seem to find the answer to this. When I launch of VM on GCP, I'm getting into the machine via the serial port due to some testing we're doing, but the there what looks like logs from process that continuously log out to the screen (assuming this is stdout when accessing via serial port?). I'm trying to turn this off but can't seem to figure out how to.
here is the version that I'm using:
cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

You can let all noisy output to be delivered to the default port ttyS0 (COM1) and enable alternative login prompt on ttyS1 (COM2).
To enable alternative serial port temporarily until next reboot:
$ sudo systemctl start serial-getty#ttyS1.service
To enable alternative serial port permanently:
$ sudo systectl enable serial-getty#ttyS1.service
Then you might connect to the enabled alternative serial port ttyS1 from Cloud Shell:
CloudShell:$ gcloud compute connect-to-serial-port my-vm --zone=my-zone --port=2

You have 2 way to deactivate the serial ports, as described in the documentation
Either you deactivate it on a specific VM with a metadata value
Or you can apply an organization policy to avoid the serial port use in your organisation, on folders or on an entire project. (We applied this in my company, for security reasons)

Related

Sandboxing to allow multiple processes open the same port

Background
I have a command-line application that I use to connect to a remote device on port 1234. I cannot change the port number, and I do not have access to the source to rebuild this tool. I'm currently working in a lab where all ports except SSH are blocked. To get around this, I create a tunnel, i.e.:
ssh -L 1234:remotehost:1234 sshuser#remotehost
Now, I can just point my CLI program at localhost:1234 to connect with my CLI tool to the desired host.
Problem
This CLI tool needs to run for about an hour straight, and I have about 200 remote hosts to test with it. I would like to parallelize this task. Unfortunately, I can only create a single tunnel on my local machine using port 1234.
Question
Is there a (trivial/simple/automated) way to jail/sandbox my CLI tool so that I can launch 100 instances in parallel (i.e. via a shell script) so that each instance "thinks" it's talking to port 1234? For example, does Docker or KVM provide some sort of anonymous/on-demand compute node feature that I could setup rapidly? I'd rather not have to resort to manually deploying and managing a slew of VirtulBox hosts via vagrant.
The simple answer is that you can use multiple IP addresses locally. Each local IP address on the client will allow you to create another tunnel. Currently, you are using localhost. But your client also has an IP address. You can prove my point by trying this syntax:
ssh -f -N -L 127.0.0.1:1234:remotehost1:1234 sshuser#remotehost1 # this is default
ssh -f -N -L <local-IP1>:1234:remotehost2:1234 sshuser#remotehost2 # specifying non-default value <local-IP1>
Now, you just need to figure out how to give your client multiple IP addresses (secondary addresses). Then you can expand this beyond 2 parallel sessions.
I've also added -f and -N to your ssh syntax to put ssh into the background (-f) and to not issue any commands.
Using -R tunnels in the past, I've found that I need to enable GatewayPorts on the server (/etc/ssh/sshd_config). In the case of -L , I don't see the need. However, the ssh man-page explicitly mentioned GatewayPorts associated with the -L function. You may need to play around a bit. I just tried this out on my Mac and I was able to get it going without any GatewayPorts considerations.

Serial port unavaliable arduino

Trying to upload a code to arduino, but whether in the Arduino IDE or Arduino Create, both return this erro while uploading. Running on Linux Tara(mint 19 cinnamon).
./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -logger humantags -fqbn arduino:avr:mega:cpu=atmega2560 -build-cache /tmp -build-path /tmp/716441957/build -verbose -libraries /tmp/716441957/custom -libraries /tmp/716441957/pinned /tmp/716441957/sketch_oct8a
Sketch uses 8280 bytes (3%) of program storage space. Maximum is 253952 bytes.
Global variables use 443 bytes (5%) of dynamic memory, leaving 7749 bytes for local variables. Maximum is 8192 bytes.
Programming with: Serial
Flashing with command:/home/jesus/.arduino-create/arduino/avrdude/6.3.0-arduino9/bin/avrdude -C/home/jesus/.arduino-create/arduino/avrdude/6.3.0-arduino9/etc/avrdude.conf -q -q -patmega2560 -cwiring -P/dev/ttyACM0 -b115200 -D -Uflash:w:/tmp/arduino-create-agent734074237/sketch_oct8a.hex:i
avrdude: ser_open(): can't open device "/dev/ttyACM0": Permission denied
ioctl("TIOCMGET"): Inappropriate ioctl for device
ioctl("TIOCMGET"): Inappropriate ioctl for device
1#
First, check the port in your IDE. In Arduino tools->port
If the port is hidden or you can not move the cursor over this then run this commands in your terminal.If everything ok then skips this and follow the second part.
sudo apt-get install librxtx-java -y
sudo usermod -aG dialout $USER
sudo apt-get install gnome-system-tools
2#
After this again check the first method. If it is not working then run this commands
ls -l /dev/ttyACM*
sudo usermod -a -G dialout <username>
You probably have another program running which is already using this port.
You should close most other programs like putty or another serial monitor app.
Otherwise, try to reconnect the Arduino to the PC.
I know that these ideas below come from using a Teensy, but they may help you.
Sometimes there are the ACM* ports listed in the Arduino IDE. Try looking at the ser ports. I know when I am running my Teensy, sometimes I have them switched and need to select the correct one.
Also, from my experience with the Teensy, you might need to add a udev rule to allow permissions to access the port from non-root user. Here is the link that shows the udev file.
There is no direct way to solve this issue. In addition to it, you are not using an IDE. I will list the things you need to check, I am sure this will solve your problem.
I am not good at Linux environment so I will refer to applications names as window, you go the corresponding application in Linux.
Go to linux device manager and see for your arduino board. It should have proper naming like "arduino uno at port 3", then use the correct port in your command. If this name does not come properly then it means Driver is not available in your machine. So, go to step2.
Find the driver online and install it in your system, I am not sure about the support of linux with arduino, once it is done please repeat step1.
So, I conclude in short that you do not have the proper driver (which is strongly believe) or pointing the wrong port. I am not an expert with the udev rules, but it is definitely an issue you can experience with these kinds of micro-controllers.

Serial Ports Linux vs Windows

I am having issues with my pyserial program on Ubuntu 16.
I am trying to send a break command to a hardware device using pyserial. I wrote a python script that:
Sets the port/baud/parity/bytesize/...
Opens the port
Sends a break command
Reads the return message from the device.
I run the script on my Ubuntu 16.04 machine and I get zero response, it just hangs or eventually timeouts. I copy the same script to my Windows machine, change the port (from /dev/ttyUSB0 to COM#) and my script works perfectly, gets a response from the device immediately.
When I run the script on Ubunutu I have to give permissions to the port (sudo chmod 666 /dev/ttyUSB), or I get permission denied errors when opening the port. Not sure if this matters.
Does anyone have any insight on what might be going on? I know Windows and Linux handle serial/com ports differently but I am a newbie to both Linux and serial so not sure if I am missing something.
I am using this USB to Serial cable (http://www.ugreen.com.cn/product-681-en.html) and I had to install some drivers. I connected the serial read/write pins and tested to make sure data is going through (which it is) so I know that works.
import serial
ser = serial.Serial()
ser.port = '/dev/ttyUSB0' # or COM12 on windows
ser.baudrate = 9600
ser.parity = serial.PARITY_NONE
ser.bytesize = serial.EIGHTBITS
ser.stopbits = serial.STOPBITS_ONE
ser.open()
ser.send_break(duration=0.9)
print(ser.read(10))
First off, you need to have proper permissions for accessing serial ports. It can be done by including your user into the group dialout:
sudo usermod -aG dialout <user>
You need to restart the system to complete it.
To avoid of some information to remain in buffers, you may need to clear read and write buffers before serial port operations:
pyserial 3.0:
ser.reset_input_buffer()
ser.reset_output_buffer()
pyserial 2.7 or earlier:
ser.flushInput()
ser.flushOutput()
Don't forget to close a port after all operations being done. Hope this helps.
First forget about your app and focus on the port troubleshooting, use putty in serial mode for sending a few terminal chars using this port. Use a jumper for conecting DB9 pin 3 to pin 2(rx and tx) an validate that you receive an echo of each character you type.

Trouble locating my serial ports using bash on Windows 10

I want to be able to read from serial ports on my computer and write to a file. Inside /dev (using Bash shell on Windows 10) I can't seem to locate my USB serial ports (I have tty, tty0, tty1, and that's it for tty).
Is it located somewhere else, or even accessible through the bash shell? I just want to be able to know how to access it at this point.
In device manager, COM4 shows up under ports when I plug in my USB. I also ran the command wmic path Win32_SerialPort in the Windows command prompt and it said "No Instance(s) Available." So I'm very confused as to how I can view my Serial Ports and why they aren't showing up in certain instances.
Any clarification on how serial ports work, especially with USB, would be greatly appreciated, as I am pretty new with this stuff.
Soon, Windows will officially support serial on the Windows Subsystem for Linux (WSL). The COM_n_ ports will be available at /dev/ttyS_n_
Mapping:
COM1 >> /dev/ttyS0
COM2 >> /dev/ttyS1
...
COM192 >> /dev/ttyS191
A good functional description can be found here:
https://blogs.msdn.microsoft.com/wsl/2017/04/14/serial-support-on-the-windows-subsystem-for-linux/
NOTE: At time of writing this feature is only available on the insider builds.
I have the same problem. Apparently you still can`t use serial ports in Bash on Ubuntu on Windows (BoUoW).
You can do basic read and write operations using socat. I used Cygwin to create a socat server that sees my serial ports. I had problems with DTR and RTS pins though.
With socat you can create virtual serial ports or forward a serial port over TCP. (And much more.)
In Cygwin serial ports are listed under /dev/ as ttyS*.
For example COM3 is /dev/ttyS2 and COM4 is /dev/ttyS3.
Start the server in Cygwin with
socat -d -d -d TCP4-LISTEN:2022,reuseaddr,fork /dev/ttyS3
Start the client on BoUoW with
socat PTY,link=/tmp/vmodem0 TCP:localhost:2022
This will create a virtual serial port in BoUoW at /tmp/vmodem0 that is connected to COM4 on your machine.

Forwarding X11 without SSH? How do I run local apps on another Pc running X Server?

I am using Cygwin X and Debian. I can forward my X session via SSH but what happens is that I seem to loose the display forwarding in the X session once in a while (from Cygwin to Linux). So i am guessing that that is an imnplementation thing with Cygwin because I never loose X11 display in the same ssh session when I use Linux to Linux.
This also happens when a X11 forwarded app tries to fork another process lets say I run Thunderbird and I click on a url inside an email. Naturally Thurderbird will try to start the default web browser but it is not doing it with Cygwin X server and here is the message I get when SSH session gives up the display for various reasons that I am not able to know.
"Error: cannot open display: localhost:10.0"
The other issue is that since the ssh gives up the display variable, I have to restart my ssh session to get it working which also kills other apps that I might be running during the ssh session.
Anyway after struggling with this for a while I am thinking that I want to be able to open my apps on another display without using ssh forwarding. I am using it internally and it is almost a closed lan so I am not worried about the security for now. I just want to be able to run the app on the Linux then see the app on the Pc that is running Cygwin.
I tried basic DISPLAY variable thing like "export DISPLAY=MY_CYGWIN_PC_IP:0.0" (on Linux Pc) but it does not work.
So I am wondering about how I can achieve this. What are the proper settings to achieve what i need?
Your direction was OK. export DISPLAY is what you want. But it is not enough.
On the target, you need to type
xhost +from.where.the.windows.are.coming.com
It gives the X server the permission to allow remote windows from this computer.
Beware, it is not really secure! A possible attacker could not only windows shown by you, but even control your mouse/keyboard. But for simple solutions, or if you can trust the remote machine and the network between you, it may be ok.
If not, there is an advanced authorization, based on preshared keys. It is named xauth. Google for xauth.
The Xorg server has an option to disable the remote windows, and there are distributions, (f.e. ubuntu!) who turn this option by default on. You can test it - if you can telnet to the tcp port 6000, it is allowed.
If you are using ssh -X, don't. Use ssh -Y
Cygwin XWin server randomly loses connection
Basically to work as old times , we need enable xdmcp on display manager and use X11 , Xwayland seems to me that doesn't work either.
sddm doesn't support xdmcp , but gdm does , you need edit /etc/gdm/custom.conf and add
[security]
DisallowTCP=false
[xdmcp]
Enable=true
xhost + ip_of_remote_computer
echo $DISPLAY (the number of the display usually :0 or :1)
after you can verify :
netstat -l | grep xdmcp
udp 0 0 0.0.0.0:xdmcp 0.0.0.0:*
lsof -i :xdmcp
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
gdm 862335 root 12u IPv4 71774686 0t0 UDP *:xdmcp
on remote host :
export DISPLAY="ip_of_server:0" (see if is 0 or other number in echo $DISPLAY on server mention above )
xclock &
References:
http://www.softpanorama.org/Xwindows/Troubleshooting/can_not_open_display.shtml
https://tldp.org/HOWTO/html_single/XDMCP-HOWTO/
https://wiki.archlinux.org/title/XDMCP

Resources