creating PowerShell function to use specific port for tunnel - powershell

I am writing a function to take a port as input for tunneling as below.
function tunnel($x){
ssh -N -L localhost:$x:localhost:$x user#server.com
}
However I am getting an error as
(base) PS C:\Users\abc> tunnel(8888)
Bad local forwarding specification 'localhost:8888'

Related

use existing SSH_AUTH_SOCK to execute commands on remote server

I connect to my work server (workserver1.com) from my local PC (localhost) using SSH and execute a bunch of commands on workserver1.
Below are the commands I execute using SSH
1) run script on server collect production data and put it in a txt
ssh -A workserver1.com 'python3 /usr/local/collect_data_online.py 2>&1 | tee /home/myname/out.txt'
$ please input your dynamic token: <manually input credential token generated every 15s>
2) filter lines I need and put in a dat file
ssh -A workserver1.com "grep 'my-keyword-cron' out.txt | grep -oP '({.*})' | tee workserver2.dat"
$ please input your dynamic token: <manually input credential token again>
3) send data collected in 2) and send to workserver2 which could only access through workserver1**
ssh -A workserver1.com 'curl workserver2.com --data-binary "#workserver2.dat" --compressed' "
$ please input your dynamic token: <manually input credential token 3rd time>
In each steps above , I actually created 3 completed different socket with workserver1.com. I got this info from running command below on remote server
$ ssh -A workserver1.com 'printenv | grep SSH'
SSH_CLIENT=10.126.192.xxx 58276 22
SSH_SESSION_ID=787878787878787878
SSH_TTY=/dev/pts/0
SSH_AUTH_SOCK=/tmp/ssh-XXXXKuJLEX/agent.29291
SSH_AUTH_CERT_SERIAL=666666666
SSH_AUTH_CERT_KEY=myname
# SSH_CONNECTION changes each time I make a SSH request to workserver1.com. so I need repeatedly input dynamic token manually
SSH_CONNECTION=10.126.192.xxx 58276 10.218.35.yyy 22
On my localhost I can also see SSH sock which used for the SSH connection
$ SSH_AUTH_SOCK=/tmp/ssh-localhost/agent.12345
My question is , is there a way to using single existing socket to avoid making multiple SSH connections and just input the dynamic token once. I hope I could use existing sock to interactively type commands to this SSH server and collect outpu/data as I want , just like on my localhost
What's in my mind is
1) socat can I run some command on localhost like
socat UNIX-CONNECT:$SSH_AUTH_SOCK,exec:'commands I want to execute' - ==> possible to get an interactive client&server shell?
2) is there any ssh option I could use ?
I am new to socat and not familiar with ssh except some commonly used commands
Thank you for your help in advance
The solution is open the first connection with '-M'
First use ControlMaster and ControlPath in ~/.ssh/config as below:
host *
ControlMaster auto
ControlPath ~/.ssh/ssh_mux_%h_%p_%r
And when connect toremote host the very first time, add '-M'
ssh -M $remotehost
Then in follow ssh connection with the same host you could just use
ssh $remotehost

SNMPD to configure as Proxy agent

Am configuring SNMPD to acts as proxy agent between SNMP manager(snmpb browser) and Network devices in centOS by referring https://net-snmp.sourceforge.io/wiki/index.php/Snmpd_proxy. After adding the <proxy -Cn testname -v 3 -u testUser -a MD5 -A "PasswordA" -x DES -X "PasswordX" -l authPriv ipaddress .1.3> in snmpd.config file, getting the below mentioned error on that line.
Error: failed to parse proxy args.
Kindly help me to resolve this.

What does it mean when I test SSH connection to GitHub it says terminating, 1 bad configuration options?

Using Gitbash, I made an SSH and I tried to test it writing in terminal:
$ ssh -T git#github.com
What returns is:
.ssh/config line 3: keyword identityfile extra arguments at end of line
.ssh/config: terminating, 1 bad configuration options
What does that mean?

Can't connect Docker CLI to the remote Docker demon inside minikube

I can't connect Docker CLI to the remote Docker demon inside minikube.
I've done minikube delete and then minikube start --driver=hyperv but when I do & minikube -p minikube docker-env | Invoke-Expression it comes back with a weird error which is:
You: The term 'You' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Invoke-Expression: Cannot bind argument to parameter 'Command' because it is an empty string.
Invoke-Expression:
Line |
1 | & minikube -p minikube docker-env | Invoke-Expression
| ~~~~~~~~~~~~~~~~~
| The string is missing the terminator: '.
Can anybody help with this?
This is a community wiki answer posted for better visibility. Feel free to expand it.
As already discussed in the comments the solution is to use the minikube docker-env command:
minikube docker-env
Configure environment to use minikube’s Docker daemon
Synopsis
Sets up docker env variables; similar to $(docker-machine env).
minikube docker-env [flags]
Notice the --shell option:
--shell string Force environment to be configured for a specified shell: [fish, cmd, powershell, tcsh, bash, zsh], default is auto-detect

How to get the IP address used by a Parallels VM from the host?

Parallels has a command line API which is documented here
>prlctl list
UUID STATUS IP_ADDR NAME
{ca50aac6-caa6-47a6-9bfe-e38f6261cb8d} running - win7
Still, even with this the IP_ADDR reported is always empty, even if the machine is running as has an internet connection.
How can I find the IP of the machine from the guest? I need a way to connect to the guest, by using a domain name or an IP.
If it's a Windows VM, you can get the IP with the following command from the host:
prlctl exec "VM Name" ipconfig | grep "IPv4" | grep -o '\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}'
For a *nix VM:
prlctl exec "VM Name" ifconfig eth1 | grep "inet " | grep -o 'addr:\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}' | grep -o '\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}\.\d\{1,3\}'
if you want to access the machine using SSH there is a built in command that can help with this.
prlctl enter <VM_ID|VM_NAME>
This will open a prompt as root to the VM
if you want the IP for any other reason there is another way to get it
prlctl exec <VM_ID|VM_NAME> ifconfig
The exec command from prlctl will execute the ifconfig command on the host linux machine (if using windows do ipconfig instead of ifconfig)
All the output of the ifconfig will be printed on your terminal and the ip will be clearly visible in the output
I stumbled upon this today and found it questionable that the list command shows an IP_ADDR but never the IP. I checked the most recent docs for the prlctl command and its states:
-f, --full
Shows the real IP address(es) for running virtual machines.
Providing this flag displays the IP addresses for me
prlctl list -f