ssh to aws instance encoding issue - ssh

I'm trying to connect to an EC2 instance on AWS, and I'm getting this as the command prompt:
]133;C;]133;D;130]1337;RemoteHost=ec2-user#master]1337;CurrentDir=/home/ec2-user]133;A[ec2-user#master ~]$ ]133;B
I'm using gnome-terminal on Ubuntu 16.04. How can I fix this?

You can change your prompt by changing the variable PS1.
Try to run the line:
PS1='\u#\h:\w\$'
If you like it you can add this line to your .bash_profile.
This will set the prompt to user#host:cwd$
The strange "]133;" is the setting of the color in the prompt
For reference the default prompt for raspian is:
PS1=\[\e]0;\u#\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w \$\[\033[00m\]

Related

Set host ip in run parameters Intellij with WSL2

I have a run configuration setup for a server tool. I want to run it in WSL2 environment from an Intellij run task. This works great but I need to manually set the Windows host IP whenever I restart the WSL2. To get the host IP I want to use this grep command:
grep -o -P "(?<=nameserver )[0-9\.]+" /etc/resolv.conf
I played with the configuration and tried something like this
This didn't work, because the grep command didn't get executed. It worked as expected when I used it in the console.
Trying the same thing with the enviroment variable didn't succeed as well.
I saw that it is possible to setup a "before run task". Maybe it is possible to do it with this option?

Apache Airflow command not found with SSHOperator

I am trying to use the SSHOperator to SSH into a remote machine and run an external application through the command line. I have setup the SSH connection via the admin page.
This section of code is used to define the commands and the SSH connection to the external machine.
sshHook = SSHHook(ssh_conn_id='remote_comp')
command_1 ="""
cd /files/232-065/Rans
bash run.sh
"""
Where 'run.sh' runs the shell script:
#!/bin/sh
starccm+ -batch run_export.java Rans_Model.sim
Which simply runs the commercial software starccm+ with some options I have specified.
This section defines the task:
inlet_profile = SSHOperator(
task_id='inlet_profile',
ssh_hook=sshHook,
command=command_1
)
I have confirmed the SSH connection works by giving a simple 'ls' command and checking the output.
The error that I get is:
bash run.sh, error: run.sh: line 2: starccm+: command not found
The command in 'run.sh' works when I am logged into the machine (it does not require a GUI). This makes me think that there is a problem with the SSH session and it is not the same as the one that Apache Airflow logs into, but I am not sure how to solve this problem.
Does anyone have any experience with this?
There is no issue with SSH connection (at least from the error message). However, the issue is with starccm+ installation path.
Please check the installation path of starccm+ .
Check if the installation path is part of $PATH env variable
$ echo $PATH
If not, then install it in the standard locations like /bin or /usr/bin etc (provided they are included in $PATH variable), or export the installed director into PATH variable like this,
$ export PATH=$PATH:/<absolute_path>
It is not ideal but if you struggle with setting the path variable you can run starccm stating the full path like:
/directory/where/star/is/installed/starccm+ -batch run_export.java Rans_Model.sim

vscode cant ssh connect "The process tried to write to a nonexistent pipe"

I am able to ssh on my windows 10 computer using ubuntu subsystem when I run the command:
/mnt/c/Users/marti/Downloads$ sudo ssh -i credfile.pem ec2-user#3.333.33.333
Where I have a file located at /mnt/c/Users/marti/Downloads/credfile.pem
I am trying to get VSCode's ssh extension to work but it keeps failing with an error "The process tried to write to a nonexistent pipe"
In my vscode settings it points to my ssh config file:
In order to connect I click the green bottom left corner of my vscode window and select the first option 'remote-ssh connect current window to host'
I paste in my command, hit enter, it prompts me to choose either mac/win/linux and I pick linux.
But it then just leads to an error saying it tried to write to a nonexistent pipe?
[20:50:27.876] "install" terminal command done
[20:50:27.877] Install terminal quit with output: The process tried to write to a nonexistent pipe.
[20:50:27.877] Received install output: The process tried to write to a nonexistent pipe.
[20:50:27.883] Resolver error: Error: The process tried to write to a nonexistent pipe
Is there something else I need to setup or change for my vscode ssh connection to work?
Instead of pasting your command, you should code the same command in your .ssh/config file.
Add in it:
Host ec2
Hostname 3.333.33.333
User ec2-user
IdentityFile C:\path\to\credfile.pem
Then you will be able to select the entry 'ec2' after selecting 'remote-ssh connect current window to host'

'xterm-new': unknown terminal type

Replicating the error:
I am using iTerm2 on Macbook (OS X Yosemite)
I ssh into a remote instance and tried to run the clear command and this error is shown:
'xterm-new': unknown terminal type.
Not only for the clear command but the same error is displayed for several other commands and the command does not execute as expected.
The error occurs only when I use iTerm2 and not when I use the default Mac Terminal. So I am guessing this problem has something to do with iTerm2 and not the virtual machine.
How can I solve this problem with iTerm2?
As mikyra pointed out in the comments above, setting the environment variable TERM=xterm-256color solves the problem.
To summarize:
# Run the following commands on the local machine's bash prompt
echo "export TERM=xterm-256color" >> ~/.bashrc
source ~/.bashrc
ssh into remote machine and run the commands you like. The same xterm-new error should not occur now.

How to run a script file remotely using SSH

I want to run a script remotely. But the system doesn't recognize the path. It complains that "no such file or directory". Am I using it right?
ssh kev#server1 `./test/foo.sh`
You can do:
ssh user#host 'bash -s' < /path/script.sh
Backticks will run the command on the local shell and put the results on the command line. What you're saying is 'execute ./test/foo.sh and then pass the output as if I'd typed it on the commandline here'.
Try the following command, and make sure that thats the path from your home directory on the remote computer to your script.
ssh kev#server1 './test/foo.sh'
Also, the script has to be on the remote computer. What this does is essentially log you into the remote computer with the listed command as your shell. You can't run a local script on a remote computer like this (unless theres some fun trick I don't know).
If you want to execute a local script remotely without saving that script remotely you can do it like this:
cat local_script.sh | ssh user#remotehost 'bash -'
It works like a charm for me.
I do that even from Windows to Linux given that you have MSYS installed on your Windows computer.
I don't know if it's possible to run it just like that.
I usually first copy it with scp and then log in to run it.
scp foo.sh user#host:~
ssh user#host
./foo.sh
I was able to invoke a shell script using this command:
ssh ${serverhost} "./sh/checkScript.ksh"
Of course, checkScript.ksh must exist in the $HOME/sh directory.
Make the script executable by the user "Kev" and then remove the try it running through the command
sh kev#server1 /test/foo.sh