I need to keep ssh'ing into many-different Linux boxes (Ubuntu mostly) and every time I miss my basic aliases. Is there a way to setup aliases etc   while opening an interactive ssh a machine without tinkering with remote machines's .bashrc/.bash_profile?   Following would just execute the alias commands in a non-interactive shell on remote machine and terminate the session (as expected): kashyap@Laptop$ ssh root@ec2-1-2-3-4.compute-6.amazonaws.com "alias c=clear; alias p=pwd; alias l='ls -altr'  I would love it if I could select a file from local machine to be executed as init script on remote, but willing to settle for less.  E.g.  ssh usr@remote --init-script=/local/my_init_script_for_ssh_sessions
8381
Probably it is a weird thing I would like to achieve but: I would like to SSH to a remote host and then execute some bash commands like "alias" automatically to use them afterwards in an interactive mode. The remote host does not allow the personal environment.    Is this possible? Would "expect" do it? Or is there any other way to achieve this? Basically I would like to have my bashrc without modifying any files on the remote host.
14957
I have the following shortcut which opens an SSH instance. How can I modify it so that when SSH closes, the terminal stays open?  [Desktop Entry] Terminal=true Type=Application Name[en_US]=ssh Icon=/logo_sprite.png Exec=gnome-terminal --geometry=... --window-with-profile=... --title=... -e 'bash -c "ssh -t -i ~/dsa.key cle@12.210.9.17 sudo -s"'
116240
I just SSH'd into root, and then SSH'd again into root on the same machine. So I have two windows open both SSH'd into root on my remote machine.  From the shell, how can I see a list of these two sessions?
87946
I'm connecting to a Linux machine through SSH, and I'm trying to run a heavy bash script that makes filesystem operations. It's expected to keep running for hours, but I cannot leave the SSH session open because of internet connections issues I have.  I doubt that running the script with the background operator, the ampersand (&amp;), will do the trick, because I tried it and later found that process was not completed. How can I logout and keep the process running?
24279
I want to make an alias in my .bashrc or .bashrc_aliases file (probably the latter).  Specifically, I want to call the clang command for my *.c file I'm writing. What I'm looking for is best summed up if I provide an example:  I have program1.c written I want to be able to type (in the terminal) compile program1, and something like the following should be actually run:  clang -ggdb -std=c99 -Wall -Werror   program1.c -lcrypt -lcs50 -lm -o program1   For those who have taken Harvard's CS50 class, you will recognize this as their make command. So if the above is impossible, and you know another way to make this happen, I'm all ears. I'm trying to avoid using their VM, as my netbook isn't really up to par to handle a VM.
123733
I mistakenly have source .bash_profile in the bashrc file and vice versa. Now when I tried to ssh into the machine (ec2), it will stuck at loading bash and get connection closed in a second. Is there a way I could fix it? Could I mount the disk to another ec2 instance to fix the bash files?  Update 1: I tried the following: %  ssh -i &quot;my-pem.pem&quot; -t ubuntu@&lt;server_address&gt;.amazonaws.com &quot;/bin/bash --noprofile --norc&quot; Connection to &lt;server_address&gt;.amazonaws.com closed.  Nothing else showed up. Do you have any idea on what was going wrong? For sanity check, if I do ssh -i &quot;my-pem.pem&quot;ubuntu@&lt;server_address&gt;.amazonaws.com, the message will be ...  28 packages can be updated. 0 of these updates are security updates. To see these additional updates run: apt list --upgradable  New release '20.04.2 LTS' available. Run 'do-release-upgrade' to upgrade to it.   Last login: Mon Feb 22 23:17:41 2021 from ip Connection to &lt;server_address&gt;.amazonaws.com closed.  Solution Just ssh onto the machine and immediately do Ctrlc and fix the bash files.
118057
I have an alias that I would like to use both as a regular user and as root, via sudo. Specifically, it is this:  alias rm=trash   This works fine as a normal user, and it works fine when I use sudo -i to get a root shell prompt, but if I use sudo rm, the alias does not apply. So where do I need to put my alias so that it works in one-off sudo commands?
57376
To launch a root shell on machines where the root account is disabled, you can run one of:   sudo -i : run an interactive login shell (reads /root/.bashrc and /root/.profile) sudo -s : run a non-login interactive shell (reads /root/.bashrc)   In the Ubuntu world, I very often see sudo su suggested as a way to get a root shell. Why run two separate commands when one will do? As far as I can tell, sudo -i is equivalent to sudo su - and sudo -s is the same as sudo su.  The only differences seem to be (comparing sudo -i on the left and sudo su - on the right):    And comparing sudo -s (left) and sudo su (right):    The main differences (ignoring the SUDO_foo variables and LS_COLORS) seem to be the XDG_foo system variables in the sudo su versions.   Are there any cases where that difference warrants using the rather inelegant sudo su? Can I safely tell people (as I often have) that there's never any point in running sudo su or am I missing something?
114992
How can I make command aliases in Windows' Command Prompt like I would with bash?  I found out about doskey in , so I can do something like:  doskey ls=dir /b   ...and now the command ls acts a little more like ls on Unix.  (I type ls so often in cmd, it isn't even funny.)  But how do I get this to stick between sessions?  It goes away the next time I open cmd.exe.  (Is there something like .bash_profile?)
5539
I used the following bash to shutdown remote computers,but for each computer,I must input the password for it.Is it possible to input the password Automatically?   #!/bin/bash  ssh -t root@192.168.1.11 "sudo poweroff" ssh -t root@192.168.1.12 "sudo poweroff" ssh -t root@192.168.1.13 "sudo poweroff" ssh -t root@192.168.1.14 "sudo poweroff" ssh -t root@192.168.1.15 "sudo poweroff" ssh -t root@192.168.1.16 "sudo poweroff" ssh -t root@192.168.1.17 "sudo poweroff" ssh -t root@192.168.1.18 "sudo poweroff" ssh -t root@192.168.1.19 "sudo poweroff" ssh -t root@192.168.1.20 "sudo poweroff" ssh -t root@192.168.1.21 "sudo poweroff" ssh -t root@192.168.1.22 "sudo poweroff" ssh -t root@192.168.1.23 "sudo poweroff" ssh -t root@192.168.1.24 "sudo poweroff" ssh -t root@192.168.1.25 "sudo poweroff" ssh -t root@192.168.1.26 "sudo poweroff"
115917
How does one get ~/.bashrc aliases to evaluate $() substitutions at run time, instead of at the time that ~/.bashrc is executed (when opening a terminal)?  I run this command often enough that I would like to add an alias for it:  svn diff -r $(svn info | grep ^Revision | awk {'print $2'}):HEAD $(svn info | grep ^URL | awk {'print $2'}) | colordiff   However, when I add it to ~/.bashrc as an alias, I see that the evaluations are hard-coded to the values they had at the time I opened the terminal:  $ alias alias svnbranch='svn diff -r 178184:HEAD svn+ssh://branches/t4252 | colordiff'   If I open a terminal in ~ then I get errors:  svn: E155007: '/home/dotancohen' is not a working copy svn: E155007: '/home/dotancohen' is not a working copy svn: E155007: '/home/dotancohen' is not a working copy svn: E155007: '/home/dotancohen' is not a working copy $ alias alias svnbranch='svn diff -r :HEAD  | colordiff' $   I've tried these two variations of the alias in ~/.bashrc, they both have the same effect (as I expected):  alias svnbranch="svn diff -r $(svn info | grep ^Revision | awk {'print $2'}):HEAD $(svn info | grep ^URL | awk {'print $2'}) | colordiff" alias svnbranch="svn diff -r `svn info | grep ^Revision | awk {'print $2'}`:HEAD `svn info | grep ^URL | awk {'print $2'}` | colordiff"   How does one get ~/.bashrc aliases to evaluate $() substitutions at run time?  Additionally, how would one search for this situation in Google? I've tried to google on "bashrc substitution", "bashrc lazy substitution", and other key phrases, but I've found nothing for what I feel should be a common enough issue to find information on.
10053
I would like to create an alias to rm command in order to have a confirmation message after executing this command. So I am creating an alias like this alias rm='rm -i'. But as far as I know this is a temporary alias and it lives until you close the terminal.  As it is explained  to save alias permanently I need to execute ~/.bash_aliases or ~/.bashrc commands in terminal and add my alias there. But when I execute ~/.bashrc I get following error message :  bash: /home/bakhtiyor/.bashrc: Permission denied   When I run ~/.bash_aliases I get another error message like this:  bash: /home/bakhtiyor/.bash_aliases: File or directory doesn't exist.   What is the actual problem and how can I solve it?
12116
I have a .bash_profile in my home directory, but it isn't getting run on login. If I do the following, then things seem to be as I expect:  ssh myhost bash source ~/.bash_profile   But normally that all happens on login. Thoughts?
113826
To the disappointment of many, tab/window title can't be set anymore with --title  I use bash. I have had a few aliases I have used to connect to remote servers with.  alias c:prod='gnome-terminal --hide-menubar --profile=Production \ --title="Production Server" -e "ssh &lt;url&gt;" &amp;'   I found a workaround for GNOME 3.14+ to set title which works well in the command line once put in .bashrc  function set-title() {   if [[ -z "$ORIG" ]]; then     ORIG=$PS1   fi   TITLE="\[\e]2;$@\a\]"   PS1=${ORIG}${TITLE} }   However, this only seems to be effective if placed and called in the remote server's .bashrc i.e. I can only change the title after login.  It has no effect, whatsoever if I attempt to change the title of the new window before connecting:  alias c:prod='gnome-terminal --hide-menubar --profile=Production \ -e "bash -c \"source ~/.bashrc;set-title Production;ssh &lt;url&gt;\"" &amp;'   Setting window title on the remote feels wrong, when the terminal is running on my box, and I cannot make it work on servers either where my user does not happen to have a home directory to put a .bashrc in.  Is there a forest I can't see for the trees?
31951
Multi-hop tunnel:  I am opening a tunnel to a remote server via a jump server.  ssh ${JUMP_HOST} -l ${JUMP_HOST_USER} -L ${PORT}:localhost:${PORT} \     ssh ${REMOTE_HOST} -l ${REMOTE_HOST_USER} -L ${PORT}:localhost:${PORT}   Now when I open a connection to localhost:port it will forward to  jump:port which in turn will forward to remote:port  Run local tunnel in background:  The problem with this is that it opens a shell on remote, whereas I just want the tunnel to run in the background.  So I add the -f option to my local tunnel to request it run in the background  ssh -f ${JUMP_HOST} -l ${JUMP_HOST_USER} -L ${PORT}:localhost:${PORT} \     ssh ${REMOTE_HOST} -l ${REMOTE_HOST_USER} -L ${PORT}:localhost:${PORT}   This, however, returns an error:  Pseudo-terminal will not be allocated because stdin is not a terminal.   Presumably this error is coming from the tunnel from jump to remote, and is caused because stdin is closed when my local tunnel is daemonized.  Tell remote tunnel I won't be running a command:  I then tried running the jump-&gt; remote tunnel with -N to tell it I'm not going to be running a remote command.  ssh -f ${JUMP_HOST} -l ${JUMP_HOST_USER} -L ${PORT}:localhost:${PORT} \     ssh -N ${REMOTE_HOST} -l ${REMOTE_HOST_USER} -L ${PORT}:localhost:${PORT}   This works great - the tunnel runs in the background and I can connect successfully to remote:port by connecting to localhost:port.  Problem:  The problem I'm having is when I want to close the tunnels.  If I send a kill signal to my local ssh tunnel's pid, it will close, but the ssh tunnel running on jump remains running.  It seems that when I daemonize my local tunnel, the tunnel on jump is also daemonized.  Question:  Is it possible to run my local tunnel in the background, but when I kill it, have it shut down all the tunnels it has spawned on all remote servers?
20453
I want to run an alias inside a bash -c construct.  The  says:     Aliases are not expanded when the shell is not interactive, unless the expand_aliases shell option is set using shopt   In this example, why is the alias hi not found when setting expand_aliases explicitly?  % bash -O expand_aliases -c "alias hi='echo hello'; alias; shopt expand_aliases; hi" alias hi='echo hello' expand_aliases  on bash: hi: command not found   I'm running GNU bash, version 5.0.0(1)-release (x86_64-pc-linux-gnu).  Context: I want to be able to run an alias at idle priority, eg a script containing:  #!/bin/bash exec chrt -i 0 nice -n 19 ionice -c 3 bash -c ". ~/.config/bash/aliases; shopt -s expand_aliases; $(shell-quote "$@")"   I want to avoid using bash -i as I don't want my .bashrc to be read.
14143
I have to run a local shell script (windows/Linux) on a remote machine. I have SSH configured on both machine A and B. My script is on machine A which will run some of my code on a remote machine, machine B. The local and remote computers can be either Windows or Unix based system. Is there a way to run do this using plink/ssh?