Green's function in Thermal Field Theory Background information
Let $\beta$ be the inverse temperature 1/T, and $H$ be the Hamiltonian.
$H = H_0 + H_I$, where $H_0$ is the free Hamiltonian.
Also $S(\beta) = e^{\beta H_0}e^{-\beta H}$
Let $\phi_H(\tau)$ be a field in Heisenberg picture, and $\phi$  in Schrodinger
picture and $\phi_I(\tau)$ in interaction picture.
$$\phi_H(\tau) = e^{\tau H}\phi e^{-\tau H} $$
Then, $\phi_H(\tau) = e^{\tau H}e^{-\tau H_0}\phi_I e^{\tau H_0} e^{-\tau H} = S^{-1}(\tau)\phi_I(\tau)S(\tau)$
Now, let me come to the actual Question:
In the book "Finite Temperature Field theory" by Ashok Das (University of Rochester), the author comes up with the following derivation for the Green's function. Here, Tr is the trace, and Pr is the Time ordering operator for $0 \le \tau \le \beta$
$$G_{\beta}(\tau, \tau') = \frac{Tr e^{-\beta H} Pr \left [ S^{-1}(\tau)\phi_I(\tau) S(\tau)S^{-1}(\tau')\phi_I(\tau')^{\dagger}S(\tau') \right ]}{Tr e^{-\beta H}}\tag{1}$$
$$= \frac{Tr e^{-\beta H_0}S(\beta) Pr \left [ S^{-1}(\tau)\phi_I(\tau) S(\tau)S^{-1}(\tau')\phi_I(\tau')^{\dagger}S(\tau')\right ] }{Tr e^{-\beta H}}\tag{2}$$
$$= \frac{Tr e^{-\beta H_0}Pr\left [ S(\beta) S^{-1}(\tau)\phi_I(\tau) S(\tau)S^{-1}(\tau')\phi_I(\tau')^{\dagger}S(\tau')\right ]}{Tr e^{-\beta H}}\tag{3}$$
$$= \frac{Tr e^{-\beta H_0}Pr \left [ \phi_I(\tau) \phi_I(\tau')S(\beta)\right ] }{Tr e^{-\beta H)}}\tag{4}$$
Now how does he arrive at the last equation (4) from equation (3)? How do all those $S(\tau)$ and $S(\tau')$ terms disappear or cancel out?
 A: The S matrix has the property $S(\tau,\tau)=1$, $S(\tau,\tau')=S(\tau,\tau'')S(\tau'',\tau')$, and $S^{-1}(\tau,\tau')=S(\tau',\tau)$ (Note that in imaginary time, the S matrix is not unitary!). In the notation used in OP, only the time differences are specified as the arguments, i.e.,  $S(\tau)\equiv S(\tau_,0)$,Hence,
$$\frac{Tr e^{-\beta H_0}Pr\left [ S(\beta) S^{-1}(\tau)\phi_I(\tau) S(\tau)S^{-1}(\tau')\phi_I(\tau')^{\dagger}S(\tau')\right ]}{Tr e^{-\beta H}}=\frac{Tr e^{-\beta H_0}Pr\left [ S(\beta,\tau)\phi_I(\tau) S(\tau,\tau')\phi_I(\tau')^{\dagger}S(\tau')\right ]}{Tr e^{-\beta H}}=\frac{Tr e^{-\beta H_0}Pr\left [ S(\beta)\phi_I(\tau)\phi_I(\tau')^{\dagger}\right ]}{Tr e^{-\beta H}}.$$
Notice that the S matrices are sitting in the correct order, i.e., one starts from $\tau=0$, moves on to $\tau'$, then $\tau$, and finally to $\beta$. This sequence is denoted in short-hand by the final expression, where the time ordering "rule" orders the field insertions "properly" anyway. As such the final expression is merely a compact notation and behind the curtains, one actually has the S matrices and the field operators inserted at the correct times, as stated explicitly in the penultimate expression.
