Using environment variables to ssh into remote from Mac using Zsh - ssh

My local environment:
Mac Big Sur 11.6
Z shell
Remote system:
Ubuntu
What I would like to do is set a variable in my local environment and use that variable as my password when I ssh into the remote server, something like:
ssh user#sometesystem.com -p env(userpwd)
Is this possible?

Related

Error when opening tmux directly from ssh connection

I try to open tmux automatically when I connect to my office Computer (Mac with macOS Catalina).
I found the following solution outlined in a few Answers and a few blog posts:
ssh <hostname> -t "tmux"
When I use this I get following error:
bash: tmux: command not found
I'm confused because I can open tmux once the ssh-connection is established but not directly.
It looks like that tmux installation path is not present in your PATH variable when you ssh.
Check what is the path for tmux installation on remote machine using which tmux. And verify if you can see that path in the output of following command.
ssh <hostname> "echo $PATH"
You can either use the full path
ssh <hostname> -t "/usr/bin/tmux"
or update the PATH settings for non-interactive shell.

Fix for tput: No value for $TERM and no -T specified when running a remote shell script using SSH

I have a nodetimecheck.sh file on a server which has a command like this
echo
tput setaf 2; echo -n " What is my node's local time: "; tput setaf 7; date
When I login to my server with SSH and execute ./nodetimecheck.sh it displays properly.
However, if I try to execute the command from my local machine via ssh like this
ssh -i ~/.ssh/privkey username#serverip ./nodetimecheck.sh
It does display the time, but there is a nagging message
tput: No value for $TERM and no -T specified
Local machine running Ubuntu 18.04 LTS
Remote server on GCP running Ubuntu 18.04 LTS
Found the solution as follows. Supply the TERM=xterm as part of the ssh command
ssh -i ~/.ssh/privkey username#serverip TERM=xterm ./nodetimecheck.sh

Connecting to a server and running a file with a GUI using bash on Windows and Xming

I'm running the Linux subsystem for Windows and Xming.
I am attempting to connect via ssh to a remote server and run a GUI program in Xming.
After initiating Xming, I run the following commands:
$ export DISPLAY=:0.0
$ ssh -X user#address
$ ./gui.sh
And I get the following error:
Unable to initialize GTK: could not open display
Exporting the display after I ssh returns the same error.
I have tried using ssh -Y as well.
Is this just a limitation of bash on Windows, or am I missing something?

How to import SQL dump into Postgres DB running on Vagrant instance of Ubuntu

I am using Postgres via a vagrant instance running ubuntu-xenial-16.04-cloudimg box and I have an sql dump from another developer.
By the way, I tried using PGAdmin IV from my Win 10 host machine after I had connected to the Postgres server on the virtualbox (ubuntu) but it takes forever and not running.
How can I import this to the Postgres running on virtualbox instance?
So given an sql dump file as dump.sql.
Run vagrant ssh on an ssh client like git bash(for windows)
Put the dump file in the directory containing the vagrantfile on the host machine. As it syncs by default with the guest machine or run vagrant rsync, just to make sure.
Navigate to the vagrant directory on the host machine (eg cd ../../ for an ubuntu guest on a window host)
Run psql -h hostname -U test -d databasename -f dump.sql.
Depending on the format of the dump (normal or custom), you can use psql or pg_restore.
Check the --format option in the documentation for pg_dump
Following the simple steps below solves my problem:
After vagrant up, vagrant ssh to log into the os
Type psql command
Then create database your_db_name to create the empty db
Make sure the dump sql file is in the folder containing the vagrantfile ( cd vagrant) or a sub folder within
Write this command to import the dump file into the newly create db
your_db_name -f /path/to/the/dump.sql
I hope the steps will help you too.

Can't run tmux in Arch Linux VM

So I have installed tmux in Arch 2016.06.01. I am connected via SSH. When trying to run the program, I get this response:
tmux: invalid LC_ALL, LC,TYPE or LANG
Other programs open fine on this VM. Thanks!
I uncommented my locale in the /etc/locale.gen file and then generated it with locale-gen. Now tmux runs.